The VBA Month Function returns the month number (from 1 to 12) of a supplied date.
The syntax of the function is:
A simple example of the VBA Month function is shown below:
' Extract the month from the date "11/29/2015"
Const currDate = "11/29/2015"
Dim mthNum As Integer
mthNum = Month(currDate)
' The variable mthNum is now equal to 11.
|
After running the above VBA code, the variable mthNum holds the value 11 (November).
If the Month function is supplied with a value that cannot be interpreted as a valid date, it will return the error: