Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Lewis Evans   on Sep 03 In MS Office Category.

  
Question Answered By: Noah Evans   on Sep 03

Here's how I would handle it:
Sub DateCalc()
Dim LastMon, LastDay, CurYear
Dim CurMon, ldtStart, ldtEnd
CurYear = Year(Now)
LastMon = Month(Now) - 1
Select Case LastMon
Case 2
If (Month(DateSerial(CurYear, 2, 29)) = 2) Then
LastDay = 29
Else
LastDay = 28
End If
Case 4, 6, 9, 11
LastDay = 30
Case Else
LastDay = 31
End Select
ldtStart = Format(DateSerial(CurYear, LastMon, 1), "MM/DD/YYYY")
ldtEnd = Format(DateSerial(CurYear, LastMon, LastDay), "MM/DD/YYYY")
MsgBox ldtStart & Chr(13) & ldtEnd
End Sub
this should work no matter WHAT day  of the month  you decided to run  the
scheduled task.
It would always execute for the previous month.
hope this helps.

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Run Last month report on 5th Or get search suggestion and latest updates.


Tagged: