How to use the VBA MONTHNAME Function (Syntax + Example)

HomeVBA Functions LIST (Category Wise)How to use the VBA MONTHNAME Function (Syntax + Example)

The VBA MONTHNAME function is listed under the date and time category of VBA functions. When you use it in a VBA code, it returns the month name as a string from a valid date as per VBA. In simple words, you can extract month value a name from a date supplied.

Syntax

MonthName(Month, [Abbreviate])

Arguments

  • Month: an integer (ranging 1 to 12) representing month.
  • [Abbreviate]: A boolean value to specify if you need to a full name of the month or abbreviated name [This is an optional argument and if omitted VBA takes FALSE by default]. 
    • Use TRUE for abbreviated name (i.e. “Jan”, “Feb”, “Mar”, etc.) or FALSE for full name (i.e. “January”, “February”, “March”, etc.) 

Example

To practically understand how to use VBA MONTHNAME function, you need to go through the below example where we have written a vba code by using it:

Sub example_MONTHNAME()
Range("B1").Value = MonthName(Range("A1"), False)   
End Sub

In the above code, we have used the MONTHNAME to get the name of the month as per the value in cell A1 and we have a 1 in the cell A1 so it has returned the “January”.

Notes

  • If the value specified as month is other than an integer or a string that can’t be recognized as a number, VBA will return the run-time 13 error.

Related Functions

DATE | DATEADD | DATEDIFF | DATEPART | DATESERIAL | DATEVALUE | DAY | MONTH | WEEKDAY | WEEKDAYNAME | YEAR