Excel VBA MonthName Function

Excel VBA MonthName Function: The MonthName function in VBA returns a string with the month name for the specified month number.

Syntax

MonthName (Month, [Abbreviate])

Parameter

Month (required) – This parameter represents an integer between 1 and 12, signifying the month.

Abbreviate (optional) – This function represents a Boolean argument specifying whether the returned month name should be abbreviated or not. By default, it is set to False.

It can hold the following values:

True – It returns the abbreviated month name, i.e. "Jan", "Feb", etc.

False (default value) – It returns the full month name i.e. "January", "February", etc.

Return

This function returns a string with the month name for the specified month number.

Example 1

Sub MonthNameFunction_Example1()
 'It will return the month name for the given month number
 Dim month_name As String
 month_name = MonthName(7)
 ' The variable month_name will return the string "July".
 Cells(1, 1).Value = month_name
 End Sub 

Output

July

VBA MonthName Function

Example 2

Sub MonthNameFunction_Example2()
 'It will return the month name for the given month number
 Dim month_name As String
 'setting the abbreviation to TRUE 
 month_name = MonthName(7, True)
 ' The variable month_name will return the abbreviated string "Jul". 
 Cells(1, 1).Value = month_name
 End Sub 

Output

Jul

VBA MonthName Function

Example 3

Sub MonthNameFunction_Example3()
 'It will return the month name for the given month number
 Dim month_name As String
 'setting the date
 month_name = MonthName(Month(#2/10/2020#)) 
 ' The variable month_name will return the string "February".
 Cells(1, 1).Value = month_name 
 End Sub 

Output

February

VBA MonthName Function