Highlight all the cells containing a specific regex in Excel


Sub Flag_Cells_by_RegeXeq()
'
' Converts each text hyperlink selected into a working hyperlink
'
Dim strSearch As String
Application.ScreenUpdating = False
strSearch = InputBox(Prompt:="Search String.", _
          title:="Search")
          
        If strSearch = vbNullString Then
           Exit Sub
        Else
            Dim re As New RegExp
            re.Pattern = strSearch
            re.IgnoreCase = True
            
            Dim xCell As Range
            For Each xCell In Selection
                If re.Test(xCell.Text) = True Then
                   xCell.Select
                   With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = vbYellow
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
                End If
            Next xCell
            
        End If
        
        MsgBox "Done"
'
'
End Sub

Comments

Popular posts from this blog

Find countries in a file's text using regular expressions and Perl

Make links active in Excel 2007