month text to a number. Why does this work?

sark666

Board Regular
Joined
Jul 30, 2009
Messages
169
I knew there was a way to convert a month written in text (e.g. May) to a number (5), but couldn't recall how.

I thought it was simply =Month("May") but that results in a #value error. However if you simply append any number from 0-99 it works. Actually, I don't see the logic with the appended numbers either. "May100" results in an error but "May9000" gives 5. Huh?

E.g. =Month("May0") or =Month("May84") will both return 5.

Sometimes I just accept things but usually like it to make sense. Anyone see the logic as to why this works?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Enter May84 in a cell and it will be coerced to the date 01 May 1984. That's why the MONTH function works. May is treated as text.
 
Upvote 0
Another question on this: How do you do the same in vba?

doing month("April1") in vba results in a type mismatch error and you can use application.worksheetfunction.month as month is available in vba.

Yes, I could do it via a lookup table or something but wondered if a quick solution similar to the above method would work in vba.
 
Upvote 0
That it does. Thanks again, this is handy. Hmm, I wouldn't have thought to use datevalue....

Oh and there was a typo in my vba question as you CAN'T use app.workshtfnt.month...
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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