Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub match_repl_del()
- Dim r1 As Long, rfound, vfound
- Dim w1, w2, v As Long
- Set w1 = Sheets(3) ' data sheet
- Set w2 = Sheets(2) ' target sheet
- r1 = 2 'data starting from row 2
- Do While Not IsEmpty(w1.Cells(r1, 1))
- v = w1.Cells(r1, 1)
- rfound = Application.Match(v, w2.Columns(2), 0) ' look for value
- If Not IsError(rfound) Then ' found it?
- vfound = w2.Cells(rfound, 2)
- If w1.Cells(r1, 2) <> vfound Then ' if value does not match sheet1 column b
- w2.Cells(rfound, 2) = w1.Cells(r1, 2) ' update based on origin sheet
- lastC = w2.Cells(rfound, 1).End(xlToRight).Column
- w2.Range(w2.Cells(rfound, 1), w2.Cells(rfound, lastC)).Interior.ColorIndex = 5
- Else ' delete entire row on sheet2 if match is not found
- w2.Rows(r1).EntireRow.Delete
- End If
- End If
- r1 = r1 + 1
- Loop
- End Sub
Add Comment
Please, Sign In to add comment