I have a VBA code that will parse out values in a text field in excel that starts with CS or cs followed by 8 digits and add those values in the same row in the empty columns to the right. What I want is for this macro to apply for the entire active sheet, search Column D for values that start with CS or cs followed by 8 digits and parse them out in the same row to the right starting at Column S going right as needed (there could up to 10 CS######## numbers in a single text cell that would need to be parsed out 10 columns to the right from Column S to Column AB)
Thank you my crazy smart Forum members for you expertise!
Here is the code that will parse out for a single active cell:
Sub GetEventIndicators()
Dim rExp As Object, allMatches As Object, match As Object
Dim specialReqs As String, eventIndicator As String
Dim row As Integer, col As Integer
specialReqs = ActiveCell.Value
row = ActiveCell.row
col = ActiveCell.Column
Set rExp = CreateObject("vbscript.regexp")
With rExp
.Global = True
.MultiLine = False
.Pattern = "[cC][sS]\d{8}"
End With
Set allMatches = rExp.Execute(specialReqs)
For Each match In allMatches
eventIndicator = match.Value
'Debug.Print "Event Indicator: " & eventIndicator
col = col + 1
Cells(row, col).Value = UCase(eventIndicator)
Next
End Sub
Bookmarks