I've got two cells with a beginning date, and another with an end date.
I'm assigning macros to buttons labelled "WTD", "YTD", "MTD", i.e. week to date, year to date, month to date.
I can work out month to date in formulas pretty easily. It's =DATE(YEAR(today()),MONTH(today))-1,DAY(today))). So cell A1 is today(), A2 is =DATE(YEAR(today()),MONTH(today))-1,DAY(today))
However, I have no idea how to do this in VBA. I've been playing around.
This doesn't work the same way as in formulas.Sub Button4_Click()
ActiveSheet.Range("A1").Value = Date - DateSerial(Year(date), Month(Date)-1, Day(Date))
ActiveSheet.Range("A2").Value = Date
End Sub
Bookmarks