Hello Dave,
Provided that string you want to extract is always between the words "Begin" and "End" this macro will work. The case of the words is ignored in the search. A variable labeled Cnt is counter for the number of strings found. You can place additional code after this to what you want with the extracted string. If you have any questions or need help expanding the code, you can contact me via email LeithRoss@aol.com.
Sub ExtractString()
Dim Cnt As Long
Dim NextIndex As Long
Dim StartIndex As Long
Dim StrPos As Long
Dim ExtractStr As String
SearchStr = " Beginhere is my test string.end Beginnew test string.end"
StartIndex = 1
Do
StrPos = InStr(StartIndex, SearchStr, "Begin", vbTextCompare)
If StrPos < 1 Then
Exit Do
Else
StartIndex = StrPos + 5
NextIndex = InStr(StartIndex, SearchStr, "End", vbTextCompare)
If NextIndex > 0 Then
ExtractStr = Mid(SearchStr, StartIndex, NextIndex - StartIndex)
Cnt = Cnt + 1
End If
End If
Loop
End Sub
Sincerely,
Leith Ross
Bookmarks