VBA Function: MonthName

The VBA MonthName function returns the name of the month based on the month number (from 1 to 12).




MonthName(number, abbreviation)

Examples of Usage

Using the MonthName function to display the names of the 12 months:

Sub example()
    MsgBox MonthName(1) 'Returns: January
    MsgBox MonthName(2) 'Returns: February
    MsgBox MonthName(3) 'Returns: March
    MsgBox MonthName(4) 'Returns: April
    MsgBox MonthName(5) 'Returns: May
    MsgBox MonthName(6) 'Returns: June
    MsgBox MonthName(7) 'Returns: July
    MsgBox MonthName(8) 'Returns: August
    MsgBox MonthName(9) 'Returns: September
    MsgBox MonthName(10) 'Returns: October
    MsgBox MonthName(11) 'Returns: November
    MsgBox MonthName(12) 'Returns: December
End Sub

The MonthName function can also display the abbreviated version of the month by entering True as the second argument:

Sub example()
    MsgBox MonthName(1, True) 'Returns: Jan
    MsgBox MonthName(2, True) 'Returns: Feb
    MsgBox MonthName(3, True) 'Returns: Mar
    MsgBox MonthName(4, True) 'Returns: Apr
    MsgBox MonthName(5, True) 'Returns: May
    MsgBox MonthName(6, True) 'Returns: Jun
    MsgBox MonthName(7, True) 'Returns: Jul
    MsgBox MonthName(8, True) 'Returns: Aug
    MsgBox MonthName(9, True) 'Returns: Sep
    MsgBox MonthName(10, True) 'Returns: Oct
    MsgBox MonthName(11, True) 'Returns: Nov
    MsgBox MonthName(12, True) 'Returns: Dec
End Sub