View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NateBuckley NateBuckley is offline
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