Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Looking for a Month Name in a String

Within my worksheet is a number of cells that MIGHT contain a name of
a Month

white mothistled January holdew February tracour December necters
exally slopers
tracing sentagen March samputs twistwased June unent chama puls
moperveyeberannochas micracadwatextilitiously
hung flamons cons bradritabol cashortimizes red

Is there a way programmically to loop thru each cell and search for
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
"Nov", Dec"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default Looking for a Month Name in a String

This could work, I wasn't sure what order you have your data in your cells so
I'm presuming they're all just down on colum, but you can change to suit your
needs.

I'm sure there will be a better way, but this should work (not had chance to
test it)

Option Explicit

Public Sub loopAndFindMonths()
size = Sheets("SheetName").Cells(Rows.Count, "A").Row
Dim i As Long
For i = 1 To size
splitUpString Sheets("SheetName").Cells(i, 1).Value, i
Next i
End Sub
Private Sub splitUpString(str As String, rowAt As Long)
Dim splitString() As String
splitString = split(str, " ")
Dim i As Integer
For i = 0 To UBound(splitString)
If CheckIsMonth(Mid(splitString(i), 1, 3)) Then
Sheets("SheetName").Cells(rowAt, 2).Value = Mid(splitString(i),
1, 3)
End If
Next i
End Sub

Private Function CheckIsMonth(str As String) As Boolean
str = UCase(str)
Select Case str
Case "JAN"
CheckIsMonth = True
Case "FEB"
CheckIsMonth = True
Case "MAR"
CheckIsMonth = True
Case Else
CheckIsMonth = False
End Select
End Function

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
Extract Month From A Text String George Excel Discussion (Misc queries) 4 May 12th 10 01:18 AM
Looking for a Month Name in a String wutzke Excel Programming 3 March 22nd 08 09:00 PM
Convert month number to string Graham Excel Worksheet Functions 6 November 16th 06 07:46 PM
copy worksheet from previous month and rename to current month Dan E. Excel Programming 4 December 8th 05 09:40 PM
Lookup the month in a date string 01/03/05 Una Excel Worksheet Functions 1 March 30th 05 09:45 AM


All times are GMT +1. The time now is 09:57 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"