【VBA】Get The beginning and end of this month

You can get
“The beginning and end of this month”!

Use the following function:
 Date function
 Month function
 Year function
 DateSerial function

PR

VBA Code

As an example, get The beginning and end of this month.

Option Explicit

Sub sampleProc()
    'Get "beginning of this month"
    MsgBox (DateSerial(Year(Date), Month(Date), 1))
    'Get "end of this month"
    MsgBox (DateSerial(Year(Date), Month(Date) + 1, 0))
End Sub

Get “beginning of this month”(Line 5).

Get “end of this month”(Line 7).

PR

Result

You got “The beginning and end of this month”!
※Due to the Excel settings, the result is in Japanese notation.

Result(beginning of this month)
Result(beginning of this month)
Result(end of this month)
Result(end of this month)
PR

FYI

For more information about following, see the following official online manual:

Date function


Month function


Year function


DateSerial function

タイトルとURLをコピーしました