Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Convert "Month" to 1, 2, 3...12

On a sheet there are numerous cells containing month names written out (e.g.
June, December, etc.). I need to convert these to their ordinal values (e.g.
January = 1; June = 6, etc.).

Can anyone post some example code that easily converts these short of having
to do a case select with 12 cases?

Thanks much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 303
Default Convert "Month" to 1, 2, 3...12

edit <find and replace<replace all

12 times


--
Greetings from New Zealand
Bill K
"quartz" wrote in message
...
On a sheet there are numerous cells containing month names written out
(e.g.
June, December, etc.). I need to convert these to their ordinal values
(e.g.
January = 1; June = 6, etc.).

Can anyone post some example code that easily converts these short of
having
to do a case select with 12 cases?

Thanks much in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Convert "Month" to 1, 2, 3...12

Sub Trial()
ActiveCell = NoMonth("June")
End Sub

Function NoMonth(MonthName As String) As Byte
NoMonth = Month(CDate(MonthName & "/1/2005"))
End Function

--
Sincerilly, thanks a lot.

Oscar Picos
Office Autom


"quartz" wrote:

On a sheet there are numerous cells containing month names written out (e.g.
June, December, etc.). I need to convert these to their ordinal values (e.g.
January = 1; June = 6, etc.).

Can anyone post some example code that easily converts these short of having
to do a case select with 12 cases?

Thanks much in advance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Convert "Month" to 1, 2, 3...12

Quartz,

You need to complete the list of month's where noted below, but this seems
to work. It operates on any cells a selection that have month names in
them:

For Each cell In Selection
Select Case LCase(cell.Value)
Case "january", "february", "march" 'take it from here, I'm too lazy
For i = 1 To 12
If Month(CDate(cell.Value & " " & "1, 2005")) = Month(CDate(i &
" " & "1, 2005")) Then
cell.Value = Month(cell.Value & " " & "1, 2005")
End If
Next i
End Select
Next cell
End Sub

hth,

Doug
"quartz" wrote in message
...
On a sheet there are numerous cells containing month names written out

(e.g.
June, December, etc.). I need to convert these to their ordinal values

(e.g.
January = 1; June = 6, etc.).

Can anyone post some example code that easily converts these short of

having
to do a case select with 12 cases?

Thanks much in advance.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Convert "Month" to 1, 2, 3...12

Try the following code:

Sub alpha()

' Declare the variables
Dim rngCell As Range
Dim strMonthName As String
Dim intMonthNumber As Integer

' Investigate the worksheet entries
For Each rngCell In ActiveSheet.UsedRange

' Initalize the variables
strMonthName = rngCell.Value
intMonthNumber = Month(DateValue(strMonthName & " 1, 1969"))

' Rewrite cell value if a month
If intMonthNumber = 1 And intMonthNumber <= 12 Then _
rngCell.Value = intMonthNumber

Next rngCell
End Sub

Regards,

Alasdair Stirling

"quartz" wrote:

On a sheet there are numerous cells containing month names written out (e.g.
June, December, etc.). I need to convert these to their ordinal values (e.g.
January = 1; June = 6, etc.).

Can anyone post some example code that easily converts these short of having
to do a case select with 12 cases?

Thanks much in advance.

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
Functions for "current" & "previous" month to calculate data Priss Excel Worksheet Functions 11 April 15th 08 06:24 PM
Function or formula to convert "text" month to number of month? Steve Vincent Excel Discussion (Misc queries) 5 May 15th 07 01: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
Function or formula to convert "text" month to number of month Steve Vincent Excel Discussion (Misc queries) 1 February 4th 06 04:19 PM
Convert "Month" to "MonthName" format from db to PivotTable Billabong Excel Programming 1 August 25th 04 09:14 AM


All times are GMT +1. The time now is 10:13 AM.

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

About Us

"It's about Microsoft Excel"