One thing to be careful of is not limiting your options. In your example,
the code is limited to numbers before or after a text string. The following
is an extension of the previous example that will handle a code that can be
split into ten parts. nnnXXnnXXXnXXXXnnnnnnXXXnX
Public Sub SplitCode()
Dim Strng As String, aChr As String
Dim i As Integer, idx As Integer
Dim str(10) As String
Strng = "123XYZ24"
For i = 1 To 10: str(i) = "": Next i
idx = 0
For i = 1 To Len(Strng)
aChr = Mid(Strng, i, 1) ' find the character
If InStr("0123456789", aChr) > 0 Then ' is it numeric
If Int(idx / 2) * 2 = idx Then idx = idx + 1
Else
If Int(idx / 2) * 2 <> idx Then idx = idx + 1
End If
str(idx) = str(idx) & aChr
Next i
Debug.Print Strng
For i = 1 To 10: Debug.Print str(i): Next i
End Sub
Another thing to be careful of is using the ASC function without a comment
that explains what you are looking for. If your code was moved to a
mainframe, your code would need to be converted to use 'F0' to 'F9'.