Reputation: 3
I am working with data that provides more than current month. Since my reporting is viewed as snapshots of performance MTD, I need to find filter the data for current month (based on yesterdays date).
I have found a couple of macros that would work based on current date and time but can't figure out how to base it off yesterdays date.
Any help will be appreciated.
Upvotes: 0
Views: 207
Reputation: 150
The Now
function in VBA will get you the current date. You can subtract 1 from it to get yesterday's date.
Sub yesterdate()
Dim vResult
vResult = Now - 1
End Sub
Upvotes: 1
Reputation: 19
You can use the DateAdd-method too, if u want to change years, months or time
Dim Yesterday As Date
Yesterday = DateAdd("d", -1, Date) '<--- Now is also possible
MsgBox Format(YesterDay, "mmmm d, yyyy")
Upvotes: 0