Replace specific matched rows on different sheets

AlarmeS

New Member
Joined
Aug 17, 2017
Messages
1
Hello everyone, I am trying to find a specific row on sheet 2 using a unique id (phone Number) and have that row replaced with the row on sheet 1 which has the same unique id (phone number). The reason this is complicated is because (sheet 1) is the filtered results for certain conditions of sheet 2 that I have copied to a new sheet using VBA.

I would like to click a button to replace the changed data from sheet 1 So the rows are not the same on both sheets. I am able to find which rows of sheet 1, are the rows on sheet 2 using phone numbers as a unique identifier (=Match(H2,Sheet2!J;J,0). But i cannot code in vba to say "replace this row (=Match(H2, Sheet2!J:J,0) on sheet 2, with the actual row from sheet 1.

The format of the columns A:V are the same on both sheets. I will also need this to loop for all values of column "H:H" (Phone Numbers). This is the only unique identifier for the columns. My list will grow on the sheet, so I need it to be example to loop up to 5000 rows (if there is a value in it).

I have basic VBA skills and I need your help! I found this code and it looks promising.
"Follow Up Call List" = Sheet 1
"Leads" = Sheet 2

Code:
Option Explicit
Sub ReplaceData()
Dim lastRw1, lastRw2, nxtRw, m
'Determine last row with data, Sheet1
  lastRw1 = Sheets("Leads").Range("H" & Rows.Count).End(xlUp).row
'Determine last row with data, Sheet2
  lastRw2 = Sheets("Call List Follow Up").Range("H" & Rows.Count).End(xlUp).row
'Loop through Sheet 2, Column H
     For nxtRw = 2 To lastRw2
'Search Sheet1 Column H for value from Sheet 2
        With Sheets("Leads").Range("H2:H" & lastRw1)
          Set m = .Find(Sheets("Call List Follow Up").Range("H" & nxtRw), lookat:=xlWhole)
'Copy Sheet2 row if match is found
            If Not m Is Nothing Then
              Sheets("Call List Follow Up").Range("H" & nxtRw).EntireRow.Copy _
              Sheets("Leads").Range("H" & m.row)
            End If
        End With
     Next
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I think your code is failing because it's trying to paste an EntireRow in Range("H" & m.row)

See if it works changing this
Code:
If Not m Is Nothing Then
     Sheets("Call List Follow Up").Range("H" & nxtRw).EntireRow.Copy _
     Sheets("Leads").[COLOR=#ff0000]Range("H" & m.row)[/COLOR]
End If

to EDIT try Rows(m.row)

Code:
If Not m Is Nothing Then
     Sheets("Call List Follow Up").Range("H" & nxtRw).EntireRow.Copy _
     Sheets("Leads").[COLOR=#0000ff]Rows(m.row)[/COLOR]
End If

M.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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