Convert month name to number

I have a drop down list with months. When a month is selected, I would then like to convert it to a month number, is there a function that can do this?

Eg. September = 9

+6
source share
6 answers

Another way

Excel Formula

=MONTH(1&A1) 

Vba

 Sub Sample() Dim MonthNm As String MonthNm = "September" Debug.Print Month(DateValue("01 " & MonthNm & " 2012")) End Sub 

or

 Sub Sample() Dim MonthNm As String MonthNm = "September" Debug.Print Application.Evaluate("=MONTH(1&" & Chr(34) & MonthNm & Chr(34) & ")") End Sub 

Replace

+33
source

Try it...

  =MONTH(DATEVALUE(A1&"1")) 

Where A1 cell contains the name of the month.

+5
source
 Sub month() Dim monthh As Integer monthh = month(Date) MsgBox monthh End Sub 

try it.

0
source

another excel formula where A1 is the cell id with the month name:

 =TEXT(DATEVALUE(A1&" 1"), "m") 
0
source

This solution did not work for me (Excel 2010), I had to shorten the month name to 3 characters and add the day number in front of the shortened line.

 =MONTH(1&LEFT(A1;3)) 
0
source

Another VBA solution

For art's sake, besides Siddhart, the valid answer is :-)

 Sub SampleTM() Dim MonthNm$: MonthNm = "September" Debug.Print MonthNm2Num(MonthNm) End Sub Function MonthNm2Num(ByVal MonthNm) As Long MonthNm2Num = Format(CDate(MonthNm & "/1 0"), "m") * 1& End Function 
0
source

All Articles