Convert month number to text without lots of IF statements- is it possible?

edeibold

New Member
Joined
May 18, 2022
Messages
13
Office Version
  1. 365
Platform
  1. Windows
I'm hoping to convert a month number (e.g. 7) to a month name (e.g. July), is there an easy way to do it? I've found several *competing* theories online of how to do it, *none* of which are correct. Does anyone know if there's an easy way of doing it? I'd like to avoid making a chain of 12 if statements if possible...

I'm using the most current version of excel 365
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this

22 10 20.xlsm
AB
17July
22February
35May
41January
512December
Month
Cell Formulas
RangeFormula
B1:B5B1=TEXT(DATE(1,A1,1),"mmmm")


Marginally shorter would be one of these, but the particular one to choose is dependant on your regional settings as to whether dates are normally d/m/y or m/d/y format whereas the one above is more robust in that it does not matter what your regional date settings are.
Excel Formula:
=TEXT("1-"&A1,"mmmm")
=TEXT(A1&"-1","mmmm")
 
Last edited:
Upvote 0
Solution
I'm hoping to convert a month number (e.g. 7) to a month name (e.g. July), is there an easy way to do it? I've found several *competing* theories online of how to do it, *none* of which are correct. Does anyone know if there's an easy way of doing it? I'd like to avoid making a chain of 12 if statements if possible...

I'm using the most current version of excel 365
If you're doing this for a vba script, you never need to use 12 if statements
Try using select case
If you're interested let me know
Tell me what your attemting to accomplish
 
Upvote 0
Try this:
VBA Code:
Sub Month_Name()
'Modified  10/19/2022  10:25:52 PM  EDT
On Error GoTo M
Application.ScreenUpdating = True
Dim ans As Variant
ans = InputBox("Enter Month Number", "Enter Number Greater then Zero and Less then 13", Month(Now()))
If ans > 12 Or ans < 1 Then MsgBox "There is no Month" & vbNewLine & "With the number" & vbNewLine & ans: Exit Sub
MsgBox MonthName(ans)
Application.ScreenUpdating = True
Exit Sub

M:
MsgBox "You entered  " & ans & vbNewLine & "That is not a proper entry"
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,973
Members
452,540
Latest member
haasro02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top