Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. Sub match_repl_del()
  2. Dim r1 As Long, rfound, vfound
  3. Dim w1, w2, v As Long
  4. Set w1 = Sheets(3) ' data sheet
  5. Set w2 = Sheets(2) ' target sheet
  6. r1 = 2 'data starting from row 2
  7. Do While Not IsEmpty(w1.Cells(r1, 1))
  8. v = w1.Cells(r1, 1)
  9. rfound = Application.Match(v, w2.Columns(2), 0) ' look for value
  10. If Not IsError(rfound) Then ' found it?
  11. vfound = w2.Cells(rfound, 2)
  12. If w1.Cells(r1, 2) <> vfound Then ' if value does not match sheet1 column b
  13. w2.Cells(rfound, 2) = w1.Cells(r1, 2) ' update based on origin sheet
  14. lastC = w2.Cells(rfound, 1).End(xlToRight).Column
  15. w2.Range(w2.Cells(rfound, 1), w2.Cells(rfound, lastC)).Interior.ColorIndex = 5
  16.  
  17. Else ' delete entire row on sheet2 if match is not found
  18. w2.Rows(r1).EntireRow.Delete
  19. End If
  20.  
  21. End If
  22. r1 = r1 + 1
  23. Loop
  24. End Sub
Add Comment
Please, Sign In to add comment