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