Hi all. I have searched high and low but I can't get to the bottom of this one. Hopefully someone here can point me in the general direction?
I have strings that could look like "N01N03N10N35" or "N 1N 7N12" or "N1N6N20"
Each substring will always start with a capital "N" followed by either two numbers, a space and a number, or no space and a number/s.
I need to do the following operations on this string:
1. Extract each substring text from the string
2. Find the start position of each substring (possibly using instr?)
3. Get the length of each substring
I have tried instr but I don't think it is possible to use a wildcard. I have had some success with split but can only extract the numbers following.
This my attempt at extracting the substring:
If NoteText Like "N##*" Then
Dim SplitStr
Dim SubStr As String
Dim NoteCount As Long
SubStr = "N"
'Use this for case sensitive count ...
NoteCount = UBound(Split(NoteText, SubStr, , 0))
'MsgBox "Case sensitive count = " & NoteCount
Dim iNote As Long
For iNote = 1 To NoteCount
Dim NoteRef As String
NoteRef = ExtractElement(NoteText, iNote, "N")
MsgBox NoteRef
Next iNote
End If
Function ExtractElement(str, n, sepChar)
' Returns the nth element from a string,
' using a specified separator character
Dim x As Variant
x = Split(str, sepChar)
If n > 0 And n - 1 <= UBound(x) Then
ExtractElement = x(n - 1)
Else
ExtractElement = ""
End If
End Function
Any help is hugely appreciated!
Thanks
Mike
Bookmarks