VBA Month Number to Name in Excel

VBA Month Number to Name

VBA Month Number to Name in Excel

VBA convert Month Number to Month Name using Excel VBA Functions. Convert or change Month Number to Name using Excel VBA MonthName function function.

Macro to Convert Month Number to Name in Excel VBA

Let us see the Macro to convert Month Number to Month Name in Excel VBA. In the below macro you can change month name which is initiated to ‘iMonthNumber’ variable. Once you change month number accordingly it displays respective month name.

'VBA Month Number to Name
Sub VBA_Month_Number_To_Name()
    'Variable declaration
    Dim sMonthName As String
    Dim iMonthNumber As Integer
    iMonthNumber = 4
    sMonthName = MonthName(iMonthNumber)
    MsgBox "Month Number : " & iMonthNumber & vbCrLf & "Month Name : " & sMonthName, vbInformation, "Month Number to Name"

End Sub

Here is the output screen shot of above macro.
VBA Month Number to Name

Instructions to use Macro

Here are the instructions to use above macro in Visual basic editor.

  • Open Visual Basic Editor(VBE) by clicking Alt +F11
  • Go to code window by clicking F7
  • Copy above specified macro or procedure
  • Paste above copied code in code window
  • Run macro by clicking F5 or Run command
  • You can see output on the screen
  • Find above specified output screenshot.

Related VBA Functions used in this article

We have used Date and DateDiff VBA functions. Click on below specified links to learn more about VBA functions.

VBA DateDiff Function VBA Date Function

Leave a Comment

Your email address will not be published. Required fields are marked *