So, I am trying to delete any rows that have duplicate data in column A. I thought this was pretty elegant compared to some of the loops I saw people asking about. However, I get an error on the line rng.RemoveDuplicates Columns:=1, Header:=xlYes. The error is Run-time error 1004. Application defined or object defined error.
Ideally, we can get the error to go away while also removing duplicates rows. Any help would be appreciated! Thanks!
Private Sub RemoveDuplicate_Click()
Dim LastRow As Long
Dim rng As Range
Dim ws As Worksheet
Set ws = Worksheets("Scorecard")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
Set rng = ws.Range("A1:K" & LastRow)
rng.RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
Also, I tried this code as well and got the same error.
Private Sub RemoveDuplicate_Click()
Dim LastRow As Long
Dim rng As Range
Worksheets("Scorecard").Activate
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Set rng = ActiveSheet.Range("A1:K" & LastRow)
rng.RemoveDuplicates Columns:=1, Header:=xlYes
End Sub