Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert month name into number

Tags:

date

excel

vba

I have dropdown box with months populated. When a month is selected I would like to then convert it to the month number is there a function that can do this?

Eg. September = 9

like image 697
HL8 Avatar asked Aug 10 '12 03:08

HL8


2 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

like image 78
Siddharth Rout Avatar answered Sep 18 '22 12:09

Siddharth Rout


Try this...

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

Where A1 cell contains month name.

like image 32
Bharat Sinha Avatar answered Sep 22 '22 12:09

Bharat Sinha