Need to know the last day of a month

piero1975

Board Regular
Joined
Nov 20, 2002
Messages
56
I cannot find a function (such as the SQL LAST_DAY) to assign to variable the last day of a month. The month is a parameter that changes every time....

Can you help me?

I hope I've explained fine this question.

Thanks!
 
Using a UDF like this you can get it
VBA Code:
Function LastDay(ByVal Dt As Date) As Long
    LastDay = DateSerial(Year(Dt), Month(Dt) + 1, 0)
End Function
 
Upvote 0
Solution
Or you can use this one to get the first day of the month:

VBA Code:
Function FirstOfNextMonth() As Date
   Dim dtm As Date
   dtm = Date
   FirstOfNextMonth = DateSerial(Year(dtm),
   Month(dtm) + 1, 1)
End Function

and then this one to get the last:

VBA Code:
Function LastOfThisMonth() as Date
   LastOfThisMonth = DateAdd("d", -1, FirstOfNextMonth)
End Function
 
Upvote 0

Forum statistics

Threads
1,226,831
Messages
6,193,208
Members
453,779
Latest member
C_Rules

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