get the latest day of the previous month

  • Thread starter Thread starter Laurent M
  • Start date Start date
L

Laurent M

hello,

i have a date variable, and i would like with VBA to get
the latest day from the previous month

many thanks
 
Function LastPrevDate(Dt As Date) As Date
LastPrevDate = DateSerial(Year(Dt), Month(Dt), 0)
End Function

Sub test()
MsgBox LastPrevDate(Now)
End Sub

HTH. Best wishes Harald
 
In case you specified VBA because you didn't think you could do it with
worksheet functions, the formula is =DATE(YEAR(TODAY()),MONTH(TODAY()),0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top