VBA: How do I get a month name from a date?


You can use the MonthName function in VBA to get the month name from a date in Excel.

Here is one common way to use this function in practice:

Sub GetMonthName()

Dim i As Integer

For i = 2 To 11
    Range("C" & i) = MonthName(Month(Range("A" & i)))
Next i

End Sub

This particular macro finds the name of the month for each date in the range A2:A11 and displays these names in the corresponding cells in the range C2:C11.

The following example shows how to use this syntax in practice.

Example: How to Get Month Name from Date Using VBA

Suppose we have the following dataset in Excel that contains information about the sales made by some company on various dates:

Suppose we would like to get the month name for each cell in the Date column.

We can create the following macro to do so:

Sub GetMonthName()

Dim i As Integer

For i = 2 To 11
    Range("C" & i)= MonthName(Month(Range("A" & i)))
Next i

End Sub

When we run this macro, we receive the following output:

Notice that column C contains the month name for each corresponding date in column A.

If you would instead like to return the abbreviated month name, you can use an optional True argument within the MonthName function as follows:

Sub GetMonthName()

Dim i As Integer

For i = 2 To 11
    Range("C" & i)= MonthName(Month(Range("A" & i)), True)
Next i

End Sub

When we run this macro, we receive the following output:

Column C now contains the abbreviated month name for each corresponding date in column A.

x