djburnheim
Technical User
I know there's lots of posts about working with dates but I can't find away of working out the number of days in month using VBA in excel. I've been playing around trying to use a loop statement to count the days until the month changes but figure there must be an easier way. I did come across a post about the same problem but it was about an Excel function available in the Analysis ToolPak, EOMonth. I'm trying to right a procedure that will simply populate cells with the days of the month...any suggestions
?
Sub NewSheet(NewMonth) 'passed from user form
dRow = 1
dColumn = 2
TYear = Year(NewMonth)
TMonth = Month(NewMonth)
TDay = ** need something to work this out
LastDay = Day(DateSerial(TYeay, TMonth, TDay)
For d = 1 To LastDay
Sheets(1).Cells(dRow, dColumn) = NewMonth
dColumn = dColumn + 1
NewMonth = NewMonth + 1
Next d
End Sub
?
Sub NewSheet(NewMonth) 'passed from user form
dRow = 1
dColumn = 2
TYear = Year(NewMonth)
TMonth = Month(NewMonth)
TDay = ** need something to work this out
LastDay = Day(DateSerial(TYeay, TMonth, TDay)
For d = 1 To LastDay
Sheets(1).Cells(dRow, dColumn) = NewMonth
dColumn = dColumn + 1
NewMonth = NewMonth + 1
Next d
End Sub