Excel Delete Duplicate Rows Based On Multiple Columns
➤ In this template, there are records that contain values in the rows between column A and column M.
There are rows with exactly the same values, namely the repeated rows. We will delete duplicate rows with the same content as the macro that we created.
To run the macro;
✔ By pressing Alt + F8 on the sheet, the Macro window opens,
✔ In the window that opened, "Delete_Same_Rows" is selected and the Run button is clicked.
✔ By pressing Alt + F8 on the sheet, the Macro window opens,
✔ In the window that opened, "Delete_Same_Rows" is selected and the Run button is clicked.
Our VBA codes to remove duplicate rows:
Sub Delete_Same_Rows()
Dim i, lastrow As Long, Rng As Range
Application.ScreenUpdating = False
lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For i = 4 To lastrow
Set Rng = Sheets("Sheet1").Range("A3:M" & lastrow)
Rng.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), Header:=xlYes
Next i
Application.ScreenUpdating = True
Set Rng = Nothing
End Sub
Dim i, lastrow As Long, Rng As Range
Application.ScreenUpdating = False
lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For i = 4 To lastrow
Set Rng = Sheets("Sheet1").Range("A3:M" & lastrow)
Rng.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), Header:=xlYes
Next i
Application.ScreenUpdating = True
Set Rng = Nothing
End Sub
We used the VBA Remove Duplicates function for deletion.
VBA Remove Duplicates function is applied to a particular range. In our macro, we defined a variable named "Rng" .
We provided the definition with that codes : Set Rng = Sheets("Sheet1").Range("A3:M" & lastrow) .
The function removes the repeated rows between A3 and the last filled cell in column M.
Columns: = Array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) codes refers to the columns that we take criteria for deleting the repeated rows (1 refers to Column A,2 refers to Column B etc.).
With this topic related , Daily Sales Report template that we use this macro can also be examined.
No comments:
Post a Comment