Help With Existing Code

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. 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:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I think you just need to remove the line of code which empties the cell before you write to it:-
Code:
Cell.Value = .Replace(Cell.Value, vbNullString)
 
Upvote 0
Thanks. FYI ZPhantom yours worked, sorry Ruddles yours didn't!
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top