Regex vba searching in workbook
Option Explicit
Sub qd_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
Sub qd_FlagCellsRegeXnoteq()
'
' 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
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 = 65115
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next xCell
End If
MsgBox "Done"
'
'
End Sub
Sub Match_regex()
'
' Converts each text hyperlink selected into a working hyperlink
'
Dim strSearch As String
Application.ScreenUpdating = False
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
Dim omatch As Match
Dim xCell As Range
For Each xCell In Selection
If re.Test(xCell.Text) = True Then
omatch = re.Execute(xCell.Value)
xCell.Value = omatch.FirstIndex
End If
Next xCell
End If
MsgBox "Done"
'
'
End Sub
Sub qd_Search_Replace_RegeXeq()
'
' Converts each text hyperlink selected into a working hyperlink
'
Dim strReplace As String
Dim strSearch As String
Application.ScreenUpdating = False
strSearch = InputBox(Prompt:="Search String.", _
title:="Search")
strReplace = InputBox(Prompt:="Replace.", _
title:="Replace")
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.Value = re.Replace(xCell.Text, strReplace)
'End If
Next xCell
End If
MsgBox "Done"
'
'
End Sub
Sub qd_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
Sub qd_FlagCellsRegeXnoteq()
'
' 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
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 = 65115
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next xCell
End If
MsgBox "Done"
'
'
End Sub
Sub Match_regex()
'
' Converts each text hyperlink selected into a working hyperlink
'
Dim strSearch As String
Application.ScreenUpdating = False
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
Dim omatch As Match
Dim xCell As Range
For Each xCell In Selection
If re.Test(xCell.Text) = True Then
omatch = re.Execute(xCell.Value)
xCell.Value = omatch.FirstIndex
End If
Next xCell
End If
MsgBox "Done"
'
'
End Sub
Sub qd_Search_Replace_RegeXeq()
'
' Converts each text hyperlink selected into a working hyperlink
'
Dim strReplace As String
Dim strSearch As String
Application.ScreenUpdating = False
strSearch = InputBox(Prompt:="Search String.", _
title:="Search")
strReplace = InputBox(Prompt:="Replace.", _
title:="Replace")
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.Value = re.Replace(xCell.Text, strReplace)
'End If
Next xCell
End If
MsgBox "Done"
'
'
End Sub
Comments