0

The following code is what ive come up with so far. I have also set the reference for regular expression 5.5.

However the match value does not show at all, am I missing something here??

Public Sub check()

Dim wb As Workbook
Set wb = ThisWorkbook

'Prepare a regular expression object
Dim myRegExp As New VBScript_RegExp_55.RegExp
Dim myMatches As MatchCollection
Dim myMatch As match
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "^\d{6,8}-[SFTG]\d{7}[A-Z]-([^-]+)$"
Set myRegExp = CreateObject("vbscript.regexp")

cellValue = CStr(wb.Worksheets(1).Cells(2, 4).Value) 
'123456-S1234567F-Scholarship Form 

If myRegExp.Test(cellValue) Then


Set myMatches = myRegExp.Execute(cellValue)


For Each myMatch In myMatches
  MsgBox (myMatch.Value)

Next

Else
End If

End Sub
6
  • Can you please provide values in wb.Worksheets(1).Cells(2, 4).Value which you want to parse. Commented Sep 26, 2013 at 4:58
  • Thank you for the reminder, i forgot to include: 123456-S1234567F-Scholarship Form Commented Sep 26, 2013 at 5:03
  • What do you want from 123456-S1234567F-Scholarship Form string ? Commented Sep 26, 2013 at 5:08
  • To see whether it matches the regex pattern Commented Sep 26, 2013 at 5:15
  • Simply play here Commented Sep 26, 2013 at 5:19

1 Answer 1

1

Removing the following line

Set myRegExp = CreateObject("vbscript.regexp")

seems to solve the issue.

I guess that's because all your initialization statements are gone when you assign myRegExp to a new object

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.