Question with a possibly very simple answer, but I'm still potty training with VBA. I'm looping through an excel array and searching a very long string for the regex pattern "\.\w*?_\w*?_Tag_\w*?"
. There is a similar example of this in this post under the accepted answer "Example 3: Loop Through Range."
Instead of finding and replacing text though, I want to display the matched search pattern from each cell of the array in a single message box. I've been searching for several hours but most of the VBA Regex examples I've found use built in functions (which don't loop through an array), but since this will be used by other folks I need to use a macro.
Here's what I have so far. I'm thinking I need another loop outside of my For Each loop but not sure how to start executing on this.
Sub TagNameList()
Dim strPattern As String: strPattern = "\.\w*?_\w*?_Tag_\w*?"
Dim Regx As New RegExp
Dim StrInput As String
Dim Rng As range
Dim LastRow As Long: LastRow = ActiveSheet.UsedRange.Rows.Count
' Set Rng = ActiveSheet.range(Cells(2, 16), Cells(LastRow, 16))
' Set RegxMatch = Regx.Execute(StrInput)
For Each cell In Rng
StrInput = cell.Value
With Regx
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = strPattern
End With
' If Regx.Test(StrInput) Then
' MsgBox (Regx.Replace(StrInput, strReplace))
' Else
' MsgBox ("Not matched")
' End If
Next
End Sub