troubleshooting Question

Excel VBA regular expression debug

Avatar of sdc248
sdc248Flag for United States of America asked on
Visual Basic ClassicMicrosoft Excel
3 Comments1 Solution372 ViewsLast Modified:
Hi:

I am trying to loop through each cell in a column and count the number of cells having 'e' in their texts but keep getting "Application-defined or object-defined error" error message. Below is what I've got. Please help.

Dim REX                 As RegExp
    Dim oMatch              As Object
    Dim count               As Integer
    Dim c                   As Range
   
    Set REX = CreateObject("VBScript.RegExp")
    With REX
        .Global = True
        .IgnoreCase = True
        .Pattern = "*e"
    End With

    count = 0
   
    For Each c In Range("F2:F500").Cells
       
        If REX.Test(c.Value) Then      'the error message is thrown here
            Set oMatch = REX.Execute(c.Value)
        End If
       
       
        If Not oMatch Is Nothing Then
            count = count + 1
        End If
       
        Set oMatch = Nothing
       
    Next c


Please note that I have added 'Microsoft VBScript Regular Expressions 5.5' to References of the project.

Thanks.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros