Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default month to number

Tim,

Can you stand one more solution?
You should be able to paste the following into a module, select the cells
with the names and run the Sub.
'---------------------------------------------------
Option Base 1 'This is required at the top of the module.

'Called by Sub ProvideTheMonth
Function GetMonthIndex(ByRef Mth As String) As Long
Dim N As Long
Dim ShortMonth As Variant
ShortMonth = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", _
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
For N = 1 To 12
If ShortMonth(N) = Mth Then
GetMonthIndex = N
Exit Function
End If
Next
GetMonthIndex = 0
End Function

'The month index is added to Column AF in the same row as the name.
'Upper case, lower case and full month names will work.
'Column AF is column 32
'Calls Function GetMonthIndex

Sub ProvideTheMonth()
Dim i As Long
Dim MthRng As Range
Dim Mth As Range
Set MthRng = Selection

For Each Mth In MthRng
i = GetMonthIndex(Left$(WorksheetFunction.Proper(Mth.V alue), 3))
If i = 0 Then
Cells(Mth.Row, 32).Value = "Check month name"
Else
Cells(Mth.Row, 32).Value = i
End If
Next
Set Mth = Nothing
Set MthRng = Nothing
End Sub
'------------------------------------------------------
Regards,

Jim Cone
San Francisco, CA
'********************
Hi,
Can you show me how to write a macro to convert a three
place month abreviation, Jan, Feb, Mar, etc., in column Y
into a number, 1, 2, 3, etc., in column AF?
Thank You.
Regards, Tim



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of days in month counted from shortened name of month & yea Tumar Excel Worksheet Functions 6 September 18th 07 03:36 PM
Converting Month Number to Month Text Abbreviation Bob Excel Worksheet Functions 10 May 12th 07 04:11 AM
Function or formula to convert "text" month to number of month? Kevin Vaughn Excel Discussion (Misc queries) 0 February 4th 06 04:45 PM
show month number as month name in Excel? Phil Hart Excel Discussion (Misc queries) 3 June 20th 05 06:12 PM
How to extract month number from month name PM Excel Discussion (Misc queries) 2 January 19th 05 03:07 PM


All times are GMT +1. The time now is 09:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"