View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
egun egun is offline
external usenet poster
 
Posts: 88
Default Last Day of the month

I usually do it something like this (VBA might not be exactly right):

Sub test()
Dim i As Integer
'
i = Last_Day_of_Month(2, 2009) ' Last day of Feb, 2009?
MsgBox "Last day of Feb, 2009 = " & i
'
End Sub

Function Last_Day_of_Month(theMonth As Integer, theYear As Integer) As Integer
Dim date1 As Date, date2 As Date
'
date1 = DateSerial(theYear, theMonth, 1) ' First day of input month/year
date2 = DateAdd("m", 1, date1) ' Add a month to get first day of next
month
Last_Day_of_Month = Day(DateAdd("d", -1, date2)) ' Then subtract one
day to get last day of input month/year
'
End Function
'

HTH,

Eric