Delete duplicate rows?
Posted by Scott on October 03, 2001 8:28 AM
I have a report that spits out reports with several duplicate rows for some reason. Some rows are duplicated as many as 20 times. I would like a macro that would run on what ever the current sheet is at the time and compare every row to the one above it. If every cell in that row is the same as the one above it that row should be deleted.
I found a macro (below) that does this for only the first column, but it doesn't work for my needs. It is possible for any cell to be the same as the one above it (especially the first cell in each row) so it is improtant that the entire row is compared--at least A:AA
Public CurRow, oZ, uY, Qq
Sub DelDups()
Qq = Application.CountA(ActiveSheet.Range("A:A")) 'Get row count before beginning
For uY = 1 To 6 'Spin thru 6 times to get them all
For oZ = 2 To Qq 'Main loop
If Cells(oZ, 1) = Cells(oZ - 1, 1) Then 'Check for dups
Cells(oZ, 1).Select 'Select the cell
Selection.Delete Shift:=xlUp 'Delete
Qq = Qq - 1 'Change loop criteria because cell gone
End If 'End
Next 'Inside loop
Next 'Outside loop
End Sub