+ Reply to Thread
Results 1 to 8 of 8

maximum days in a month

  1. #1
    james
    Guest

    maximum days in a month

    hello,
    What statement would I use to find out maximun days in a month in VBA?

    Thanks in advance

  2. #2
    Bernie Deitrick
    Guest

    Re: maximum days in a month

    James,

    Months in VBA are the same as regular months, so 31.

    But I'm guessing your question is somewhat more specific than it appears.

    What kind of days? Workdays? Weekend days? Odd numbered Wednesdays?

    HTH,
    Bernie
    MS Excel MVP

    "james" <[email protected]> wrote in message
    news:[email protected]...
    > hello,
    > What statement would I use to find out maximun days in a month in VBA?
    >
    > Thanks in advance




  3. #3
    Tom Ogilvy
    Guest

    Re: maximum days in a month

    the zeroth day of the next month is the last days of the month in question

    Dim dt as Date
    dt = Date
    lastDay = days(DateSerial(year(dt),Month(dt)+1,0))

    --
    Regards,
    Tom Ogilvy

    "james" <[email protected]> wrote in message
    news:[email protected]...
    > hello,
    > What statement would I use to find out maximun days in a month in VBA?
    >
    > Thanks in advance




  4. #4
    Tom Ogilvy
    Guest

    Re: maximum days in a month

    Here is a demo:

    Sub ABCD()
    sStr1 = ""
    For i = 1 To 12
    dt = DateSerial(2005, i, 1)
    sStr = "Last day of " & _
    Format(dt, "mmmm") & " is " & _
    Day(DateSerial(Year(dt), Month(dt) + 1, 0))
    sStr1 = sStr1 & sStr & vbNewLine

    Next
    MsgBox sStr1, , "Last Day of the Month for Year 2005"
    End Sub

    --
    Regards,
    Tom Ogilvy

    "Tom Ogilvy" <[email protected]> wrote in message
    news:[email protected]...
    > the zeroth day of the next month is the last days of the month in question
    >
    > Dim dt as Date
    > dt = Date
    > lastDay = days(DateSerial(year(dt),Month(dt)+1,0))
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "james" <[email protected]> wrote in message
    > news:[email protected]...
    > > hello,
    > > What statement would I use to find out maximun days in a month in VBA?
    > >
    > > Thanks in advance

    >
    >




  5. #5
    sebastienm
    Guest

    RE: maximum days in a month

    Hi,
    Lat day in a month i given by
    Dim d as Date
    d=date() '<--- your date here
    'last date of month
    msgbox MonthLastDay = DateSerial(Year(d), Month(d) + 1, 1 - 1)
    'day number
    msgbox Day(MonthLastDay = DateSerial(Year(d), Month(d) + 1, 1 - 1))

    Regards,
    Sebastienm

    "james" wrote:

    > hello,
    > What statement would I use to find out maximun days in a month in VBA?
    >
    > Thanks in advance


  6. #6
    sebastienm
    Guest

    RE: maximum days in a month

    okj, i'll try to re-write my previous post without error this time:
    Dim d as Date
    d=date() '<--- your date here
    'last date of month
    msgbox DateSerial(Year(d), Month(d) + 1, 1 - 1)
    'day number
    msgbox Day(DateSerial(Year(d), Month(d) + 1, 1 - 1))

    sebastienm

  7. #7
    Tom Ogilvy
    Guest

    Re: maximum days in a month

    Note that days should be signular
    lastDay = days(DateSerial(year(dt),Month(dt)+1,0))
    should be

    lastDay = day(DateSerial(year(dt),Month(dt)+1,0))

    sorry for the typo.

    --
    Regards,
    Tom Ogilvy


    "Tom Ogilvy" <[email protected]> wrote in message
    news:[email protected]...
    > the zeroth day of the next month is the last days of the month in question
    >
    > Dim dt as Date
    > dt = Date
    > lastDay = days(DateSerial(year(dt),Month(dt)+1,0))
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "james" <[email protected]> wrote in message
    > news:[email protected]...
    > > hello,
    > > What statement would I use to find out maximun days in a month in VBA?
    > >
    > > Thanks in advance

    >
    >




  8. #8
    Ron Rosenfeld
    Guest

    Re: maximum days in a month

    On Mon, 7 Feb 2005 11:05:02 -0800, "james" <[email protected]>
    wrote:

    >hello,
    >What statement would I use to find out maximun days in a month in VBA?
    >
    >Thanks in advance


    You don't have to compute it since VBA uses the same calendar.

    ====================
    Const MaxDaysInMonth As Integer = 31
    ====================

    Perhaps you mean something else?



    --ron

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1