Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Bonni Garcia   on Nov 10 In MS Office Category.

  
Question Answered By: Bin Fischer   on Nov 10

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'.

Share: 

 

This Question has 11 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on loop through a range name Or get search suggestion and latest updates.


Tagged: