Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Apr 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Excel Dates (Excel 2000)

    Hi!

    I'm trying to create a macro that gives me the current month only in a cell. I've tried using the following syntax

    With range ("Month")
    .value = month(date)

    What I end up with is the integer 4 for April which seems reasonable but when I change the cell format to Date using "M" for month it gives me January which is confusing. How can I get the right month without writing 12 "if" statements converting each integer to the correct month.

    Can anyone help?

    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel Dates (Excel 2000)

    Date formats work on dates, not on just a month number. So you need to put the current date itself in the cell, so use .Value = Date if you want a constant value, or .Formula = "=TODAY()" if you want a dynamic value. Then, formatting as "m" will result in 4, "mm" in 04, "mmm" in Apr and "mmmm" in April.

  3. #3
    New Lounger
    Join Date
    Apr 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel Dates (Excel 2000)

    Hans,

    Thanks very much. My little macro runs like a charm now!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •