Hi, I am currently trying to write a code to select all data and then delete all rows based on duplicates from a single column. I want to delete rows based on duplicates in columns A, J, E, and K. I typically do this by hand one column at a time using the Remove Duplicates tool in Data tab. However, I am trying to write a code since this is a repetitive process. The code as it currently exists seems to delete duplicates using column F four times rather than doing 4 different columns (A, J, E and K).
Sub AmgenDelDupes()
Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range
Set sht = Worksheets("Sheet1")
Set StartCell = Range("A1")
'Refresh UsedRange
Worksheets("Sheet1").UsedRange
'Find Last Row
LastRow = sht.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Select Range
sht.Range("A1:Q" & LastRow).Select
ActiveSheet.Range("A1:Q" & LastRow).RemoveDuplicates Columns:=1, Header:=xlYes
ActiveSheet.Range("A1:Q" & LastRow).RemoveDuplicates Columns:=10, Header:=xlYes
ActiveSheet.Range("A1:Q" & LastRow).RemoveDuplicates Columns:=5, Header:=xlYes
ActiveSheet.Range("A1:Q" & LastRow).RemoveDuplicates Columns:=11, Header:=xlYes
End Sub
Bookmarks