Results 1 to 2 of 2

Thread: Question

  1. #1
    New Member
    Join Date
    Aug 07
    Posts
    2

    Question

    How can I get the last day of a certain month in VB/VBA?

    This is what I have...

    Public Function LastDayOfMonth (Mn As Integer, Yr As Integer) As Date

    End Function

  2. #2
    Fanatic Member
    Join Date
    Jun 06
    Posts
    999

    Re: Question

    Use DateAdd to get the day before the first day of the following month:
    Code:
    Public Function LastDayOfMonth(Mn As Integer, Yr As Integer) As Date
      LastDayOfMonth = DateAdd("d", -1, DateSerial(Yr, Mn + 1, 1))
    End Function
    This also works:
    Code:
    Public Function LastDayOfMonth(Mn As Integer, Yr As Integer) As Date
      LastDayOfMonth = DateSerial(Yr, Mn + 1, 0)
    End Function
    For future reference, questions like this belong in the Classic Visual Basic forum.

Posting Permissions

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