Jared_Jones_23
New Member
- Joined
- Jun 24, 2011
- Messages
- 34
I have a macro that deletes duplicate rows once it is run. I was wondering if there is anyway that instead of immediately deleting the rows it could save the rows and print a message box listing the duplicate rows and then prompt them to delete them with yes or no.
Any suggestions are appreciated.
Thank you,
Jared
Sub rows()
'using nested do while loops
'we start at row 20 because row 19 has only the headers
x = 20
y = x + 1
Do While Cells(x, 1).Value <> ""
Do While Cells(y, 1).Value <> ""
If Cells(x, 1).Value = Cells(y, 1).Value And Cells(x, 2) = Cells(y, 2).Value And Cells(x, 8) = Cells(y, 8) And Cells(x, 12).Value = Cells(y, 12).Value And Cells(x, 14).Value = Cells(y, 14).Value And Cells(x, 15).Value = Cells(y, 15).Value And Cells(x, 16).Value = Cells(y, 16).Value And Cells(x, 18).Value = Cells(y, 18).Value And Cells(x, 20).Value = Cells(y, 20).Value And Cells(x, 21).Value = Cells(y, 21).Value And Cells(x, 22).Value = Cells(y, 22).Value And Cells(x, 23).Value = Cells(y, 23).Value And Cells(x, 24).Value = Cells(y, 24).Value And Cells(x, 25).Value = Cells(y, 25).Value Then
'delete if duplicate
Cells(y, 1).EntireRow.Delete
Else
y = y + 1
End If
Loop
x = x + 1
y = x + 1
Loop
End Sub
Any suggestions are appreciated.
Thank you,
Jared
Sub rows()
'using nested do while loops
'we start at row 20 because row 19 has only the headers
x = 20
y = x + 1
Do While Cells(x, 1).Value <> ""
Do While Cells(y, 1).Value <> ""
If Cells(x, 1).Value = Cells(y, 1).Value And Cells(x, 2) = Cells(y, 2).Value And Cells(x, 8) = Cells(y, 8) And Cells(x, 12).Value = Cells(y, 12).Value And Cells(x, 14).Value = Cells(y, 14).Value And Cells(x, 15).Value = Cells(y, 15).Value And Cells(x, 16).Value = Cells(y, 16).Value And Cells(x, 18).Value = Cells(y, 18).Value And Cells(x, 20).Value = Cells(y, 20).Value And Cells(x, 21).Value = Cells(y, 21).Value And Cells(x, 22).Value = Cells(y, 22).Value And Cells(x, 23).Value = Cells(y, 23).Value And Cells(x, 24).Value = Cells(y, 24).Value And Cells(x, 25).Value = Cells(y, 25).Value Then
'delete if duplicate
Cells(y, 1).EntireRow.Delete
Else
y = y + 1
End If
Loop
x = x + 1
y = x + 1
Loop
End Sub