the INSTR function has a start position argument.
Private Function m_GetNumber(Text As String) As Long
Dim lngIndex As Long
For lngIndex = Len(Text) To 1 Step -1
If Not IsNumeric(Mid(Text, lngIndex)) Then
m_GetNumber = CLng(Mid(Text, lngIndex + 1))
Exit Function
End If
Next
m_GetNumber = CLng(Text)
Exit Function
End Function
Sub X()
Dim strTest As String
Dim lngCount As Long
Dim lngIndex As Long
Dim lngShops() As Variant
Dim lngPos As Long
Dim lngStart As Long
Const SHOPS = "SHOPS"
strTest = UCase("1 shops 12 shops 3 shops")
lngCount = (Len(strTest) - Len(Replace(strTest, SHOPS, ""))) / Len(SHOPS)
ReDim lngShops(1 To lngCount)
lngStart = 1
lngPos = InStr(lngStart, strTest, SHOPS, vbTextCompare)
lngIndex = 0
Do While lngPos > 0
lngIndex = lngIndex + 1
lngShops(lngIndex) = m_GetNumber(Trim(Mid(strTest, lngStart, lngPos - lngStart)))
lngStart = lngPos + Len(SHOPS)
lngPos = InStr(lngStart, strTest, SHOPS, vbTextCompare)
Loop
For lngIndex = 1 To lngCount
Debug.Print lngIndex, lngShops(lngIndex)
Next
End Sub
Bookmarks