Results 1 to 9 of 9
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How Many Days (XP)

    Is there a function that will determine the number of days in the month if you know the month and year ie 02 and 2004.

    Thanks,
    John

  2. #2
    Platinum Lounger
    Join Date
    Jan 2001
    Posts
    3,788
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How Many Days (XP)

    With the month in A1 & the year in A2

    =DAY(DATE(A2,A1+1,0))

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How Many Days (XP)

    If the date is in A1:

    <pre>=DAY(DATE(YEAR(A1),MONTH(A1)+1,0))
    </pre>

    Legare Coleman

  4. #4
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How Many Days (XP)

    Thank you

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Posts
    1,418
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: How Many Days (XP)

    Assuming your month and year are in A1 as 02/2004, I always use "DAY(EOMONTH(A1,0))"

  6. #6
    Platinum Lounger
    Join Date
    Jan 2001
    Posts
    3,788
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How Many Days (XP)

    To use the EOMONTH function you must install and load the Analysis ToolPak add-in otherwise you will get a #NAME error.

  7. #7
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How Many Days (XP)

    Tony,

    Let's take it to the next step via code:

    Sub TestDays()
    Dim oMo As Integer
    Dim oYr As Integer
    oMo = "11"
    oYr = "2004"
    oDays = Day(Date(oYr,oMo +1,0)) 'I receive a compile error on this line
    End Sub


    I don't understand why I am receiving the compile error.

    Thanks,
    John

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

    Re: How Many Days (XP)

    DATE is a worksheet function, and its VBA equivalent is DateSerial. The VBA function Date returns the current date - like the worksheet function TODAY.

    Isn't is fun? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  9. #9
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How Many Days (XP)

    Hans,

    It now makes sense. Back to the <img src=/S/read.gif border=0 alt=read width=19 height=33> to learn a little more about DateSerial.

    Thanks,
    John

Posting Permissions

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