Re: Use of Like to extract data



Thank you both for your help.

I went through all of the data tyhat I have to use, and this is the
patter

A ###.

i.e. an optional Alpha Character followed by a space. They always
come together, or are absent together. Then up to 3 numeric
characters then a period.

Examples would be

F 1.
F 001.
676.
1.
14.
J 12.

Ron example works nicely and does what I need, however could you tell
me how to expand on your sPatter to deal with the examples I used
above? I've never worked with this type of matching before, so I'm
not sure how to change the pattern your showed me.

Thanks
b

Sub test()
Dim s(3) As String
Dim i As Long

s(0) = "abc12.xy"
s(1) = "123.abc"
s(2) = "12ab456.xyz"
s(3) = "12345." 'not sure what you want here

Dim oRegex As RegExp
Dim oMatch As Match
Dim colmatches As MatchCollection
Const sPattern As String = "\d{1,3}(?=\.)"

Set oRegex = New RegExp
oRegex.Pattern = sPattern
oRegex.Global = True

For i = 0 To UBound(s)
If oRegex.test(s(i)) = True Then
Set colmatches = oRegex.Execute(s(i))
Debug.Print colmatches(0)
End If
Next i

End Sub
==============================
--ron- Hide quoted text -

- Show quoted text -


.



Relevant Pages

  • Re: Use of Like to extract data
    ... i.e. an optional Alpha Character followed by a space. ... Dim sAs String ... Dim colmatches As MatchCollection ... Set oRegex = New RegExp ...
    (microsoft.public.excel.programming)
  • Re: PLS SUGEST VB CODE TO REMOVE INITIALS FROM NAME AND ATTACH IT
    ... Dim oRegex As Object ... Set oRegex = CreateObject ... oRegex.Pattern = sPattern ... For Each c In Selection ...
    (microsoft.public.excel.programming)
  • Re: dates within a string
    ... enter it in some cell as ... Dim oMatchCollection As Object ... Set oRegex = CreateObject ... Dim Temp As Variant ...
    (microsoft.public.excel)
  • Re: dates within a string
    ... enter it in some cell as ... Dim oMatchCollection As Object ... Set oRegex = CreateObject ...
    (microsoft.public.excel)
  • Re: IF not numbers delete
    ... Sub Test() ... Dim iLastRow As Long ... Set oRegEx = CreateObject ...
    (microsoft.public.excel.misc)