Wednesday, 27 September 2017

regex - Why is match object .Value not working as expected?

I am trying to assign a match object value to a cell value, but it is giving me compile error




Method or Data Member not found




I believe I would probably have the syntax wrong, but even after consulting online tutorials and examples, I cannot deduce what the correct syntax would be for my code.



I have looked at different examples on the web. I found this one website that showed what should have worked for me, but even that did not.

https://developer.rhino3d.com/guides/rhinoscript/vbscript-regexp-objects/



This is my code.



    Dim rng As Range
Set rng = Range("a3")

Dim ObjRegex As RegExp
Set ObjRegex = New RegExp


Dim matches As MatchCollection

With ObjRegex
.Pattern = "^Total:"
.Global = True
.IgnoreCase = True
Set matches = .Execute(rng)
End With

If matches.Count = 1 Then

Range("b1").Value = matches.Value
End If

End Sub


Ultimately, If the cell value has a match of the regex pattern then I want to copy the cell contents to another address.



Note: I have tested, and the regex does work and give a match.
The problem is in the if statement

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...