Friday, August 12, 2016

How to use the MONTHNAME Function (VBA)

Description

The Microsoft Excel MONTHNAME function returns a string representing the month given a number from 1 to 12.

Syntax

The syntax for the MONTHNAME function in Microsoft Excel is:
MonthName( number, [ abbreviate ] )

Parameters or Arguments

number
A value from 1 to 12, representing the month.
abbreviate
Optional. This parameter accepts a boolean value, either TRUE or FALSE. If this parameter is set to TRUE, it means that the month name is abbreviated. If this parameter is set to FALSE, the month name is not abbreviated.

Applies To

  • Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • VBA function (VBA)

Example (as VBA Function)

The MONTHNAME function can only be used in VBA code in Microsoft Excel.
Let's look at some Excel MONTHNAME function examples and explore how to use the MONTHNAME function in Excel VBA code:
MonthName(3)
Result: 'March'

MonthName(3, TRUE)
Result: 'Mar'

MonthName(7, FALSE)
Result: 'July'
For example:
Dim LValue As String

LValue = MonthName(3, TRUE)
In this example, the variable called LValue would now contain the value of 'Mar'.

No comments:

Post a Comment