Dazzawm
Well-known Member
- Joined
- Jan 24, 2011
- Messages
- 3,786
- Office Version
- 365
- Platform
- Windows
I have this code that extracts data that is amongst data in cells in column J and puts it in Column K. But I need it to add it on the end of the data already in the destination cell rather than overwriting it. Thanks.
Code:
Sub ExtractData()
Dim REX As Object '<--- RegExp
Dim rexMatch As Object '<--- Match
Dim rexMatchCol As Object '<--- MatchCollection
Dim Cell As Range
Dim strText As String
Set REX = CreateObject("VBScript.RegExp")
With REX
.Global = True
.IgnoreCase = True
.Pattern = "JTD" '<---change to suit if
For Each Cell In Range(Cells(2, "J"), Cells(Rows.Count, "J").End(xlUp))
If .test(Cell.Value) Then
Set rexMatchCol = .Execute(Cell.Value)
Cell.Value = .Replace(Cell.Value, vbNullString)
strText = vbNullString
For Each rexMatch In rexMatchCol
strText = strText & Chr(32) & rexMatch.Value
Next
Cell.Offset(, 1).Value = Trim(strText)
End If
Next
End With
End Sub
Last edited: