
Originally Posted by
Scott Huish
Code:
Sub GetAllHCodes()
Dim m As Object, s As String, a, n As Long
s = Range("A1")
With CreateObject("vbscript.regexp")
.Pattern = "H[0-9]{5,6}"
.Global = True
If .test(s) Then
Set m = .Execute(s)
For Each a In m
n = n + 1
Cells(n, 2) = a
Next
End If
End With
End Sub
For those who might be interested, you can produce the same results as the above code without using RegExp...
Code:
Sub GetAllHCodes()
Dim X As Long, HCodes As String, H() As String
H = Split(Range("A1").Value, "H")
For X = 1 To UBound(H)
If Not Split(H(X))(0) Like "*[!0-9]*" And InStr(H(X), " ") > 4 Then HCodes = HCodes & " H" & Split(H(X))(0)
Next
H = Split(Trim(HCodes))
Range("B1:B" & UBound(H) + 1) = Application.Transpose(H)
End Sub
Bookmarks