Find Last Day of The Month And Do Something

dgr

Board Regular
Joined
Apr 24, 2005
Messages
176
Hello,
I'm looking for an Excel macro solution. I'm using Excel 2013.

I want to determine if today is the last day of the month. If yes, do something. If no, do nothing. Could you show me the code please?

Thanks.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You will need to ensure you have the analysis toolpak add-in installed though. Developer tab > Add Ins Section > Add-Ins button > Analysis Toolpak.
 
Upvote 0
Try

Code:
Sub findDate()
Dim now As Date
Dim firstDay As Date
Dim lastDay As Date

now = Date

firstDay = DateSerial(Year(now), Month(now), 1)
lastDay = DateSerial(Year(now), Month(now) + 1, 0)

If now = firstDay Then
    'process
End If

If now = lastDay Then
    'process
End If

End Sub
 
Upvote 0
Code:
Sub Test()
If DateSerial(Year(ActiveCell.Value), Month(ActiveCell.Value) + 1, 0) = ActiveCell.Value Then
    MsgBox "Date is the last day of the month."
Else
    MsgBox "Date is Not last day of the month."
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top