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.
Table of Contents:
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.
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.