If a row contains the same data in Col A and B as the row just below it, I want to keep only the top row. In other words, if there are 10 rows that all have the same data in Col A and Col B, I want to keep only Row 1.
A macro I have used successfully on another spreadsheet won't work on this one and I don't know why! That macro is as follows -
Dim r As Long
Dim c As Long
Dim lastRow As Long
Dim lastCol As Long
Dim dup As Boolean
Dim firstRow As Long
Dim firstCol As Long
With ActiveSheet.UsedRange
firstRow = .Cells(1).Row + 1
lastRow = .Cells(.Cells.Count).Row
firstCol = .Cells(1).Column
lastCol = .Cells(.Cells.Count).Column
End With
For r = lastRow To firstRow Step -1
dup = True
For c = firstCol To lastCol
If Cells(r, c).Value <> Cells(r - 1, c).Value Then
dup = False
Exit For
End If
Next
If dup Then Rows(r).Delete
Next
Beep
End Sub
When I run this macro, it "flutters" and looks like it is working and beeps when it's finished - but has actually deleted nothing! I can't figure out why. Please help!!!
Thanks!
Janet
A macro I have used successfully on another spreadsheet won't work on this one and I don't know why! That macro is as follows -
Dim r As Long
Dim c As Long
Dim lastRow As Long
Dim lastCol As Long
Dim dup As Boolean
Dim firstRow As Long
Dim firstCol As Long
With ActiveSheet.UsedRange
firstRow = .Cells(1).Row + 1
lastRow = .Cells(.Cells.Count).Row
firstCol = .Cells(1).Column
lastCol = .Cells(.Cells.Count).Column
End With
For r = lastRow To firstRow Step -1
dup = True
For c = firstCol To lastCol
If Cells(r, c).Value <> Cells(r - 1, c).Value Then
dup = False
Exit For
End If
Next
If dup Then Rows(r).Delete
Next
Beep
End Sub
When I run this macro, it "flutters" and looks like it is working and beeps when it's finished - but has actually deleted nothing! I can't figure out why. Please help!!!
Thanks!
Janet