End of previous month

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

What function would I need to use to calculate the last
calendar day of last month.

If I run a macro on 2nd Feb I want my date to default to
31-Jan-04.

If I run it on 27th April I want it to default to 31-Mar-
04. Is this possible ?

Thanks in advance
 
In a spreadsheet cell, you can use =date. Like
'=DATE(YEAR(TODAY()),MONTH(TODAY()),0)'
In excel macros, see the dateserial function for similar types of work.
Also dateadd may help.
 
Sub test()
Dim EndofLastMonth As Date
EndofLastMonth = Date - Day(Date)
MsgBox EndofLastMonth

End Sub>-----Original Message-----
 
datLastMonth = DateSerial(Year(Now), Month(Now), 1) - 1

Basically, the first day of the current month - 1...
 
Here is one way:

Dim LastDayOfLastMonth As Date
LastDayOfLastMonth = _
DateValue(Month(Date) & "/1/" & Year(Date)) - 1

tod
 

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