Advertisement
Pastebinuser1993

Duplicates

Jun 17th, 2023
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub CommandButton1_Click()
  2.  
  3. 'Code to select data
  4.  
  5. Worksheets("Remove Duplicates").Cells.Select For sorting data
  6.  
  7. With ActiveWorkbook.Worksheets("Remove Duplicates").Sort
  8.  
  9. SetRange Range("8:8") Header = xlYes
  10.  
  11. MatchCase = False
  12.  
  13. Orientation = x/TopToBottom
  14.  
  15. Apply End With
  16.  
  17. lastrow = Worksheets("Remove Duplicates").Cells(Rows.Count, 2).End(xlUp).Row
  18.  
  19. For i = lastrow To 2 Sep by-1
  20.  
  21. If Worksheets("Remove Duplicates").Cells(i, 2).Value = Worksheets("Remove Duplicates").Cells(i-1, 2).Value Then Worksheets("Remove Duplicates").Rows(1).Select Selection.Delete shift:=xlUp
  22.  
  23. End If
  24.  
  25. Next
  26.  
  27. Worksheets("Remove Duplicates").Cells(1, 1).Select
  28.  
  29. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement