Mandar Khedekar
New Member
Suppose I am having following data in a table ,and I have to delete the duplicate rows. In this case Book1, Book11 and Book 9 should be deleted as they are duplicate entries.
Column D Column E Column F
Book Name Number of Copies Price
Book 1 45 230
Book 2 80 450
Book 3 34 100
Book 4 22 210
Book 5 11 183
Book 6 56 234
Book 7 74 543
Book 8 46 289
Book 10 89 260
Book 11 45 230
Book 11 45 230
Book 21 80 450
Book 13 34 100
Book 1 22 210
Book 50 11 183
Book 33 56 234
Book 23 74 543
Book 81 46 289
Book 9 22 470
Book 14 89 260
I did try with the below code but didnt work
LastRow = Worksheets("Sheet1").Range("D" & Rows.Count).End(xlUp).Row
For n = 1 To LastRow
With ThisWorkbook.Sheets("Sheet1").Cells(n, 1)
If .Cells(n, 1) = .Cells(n + 1, 1) Then
rowstodelete = ThisWorkbook.Sheets("Sheet1").Cells(n, 1)
Rows(rowstodelete).Select
Selection.Delete Shift:=xlUp
End If
End With
Next n
Column D Column E Column F
Book Name Number of Copies Price
Book 1 45 230
Book 2 80 450
Book 3 34 100
Book 4 22 210
Book 5 11 183
Book 6 56 234
Book 7 74 543
Book 8 46 289
Book 10 89 260
Book 11 45 230
Book 11 45 230
Book 21 80 450
Book 13 34 100
Book 1 22 210
Book 50 11 183
Book 33 56 234
Book 23 74 543
Book 81 46 289
Book 9 22 470
Book 14 89 260
I did try with the below code but didnt work
LastRow = Worksheets("Sheet1").Range("D" & Rows.Count).End(xlUp).Row
For n = 1 To LastRow
With ThisWorkbook.Sheets("Sheet1").Cells(n, 1)
If .Cells(n, 1) = .Cells(n + 1, 1) Then
rowstodelete = ThisWorkbook.Sheets("Sheet1").Cells(n, 1)
Rows(rowstodelete).Select
Selection.Delete Shift:=xlUp
End If
End With
Next n