因此,我正在尝试删除A列中具有重复数据的所有行。与我看到的人们所问的某些循环相比,我认为这很不错。但是,我在行rng.RemoveDuplicates Columns:= 1,Header:= xlYes上收到错误。该错误是运行时错误1004。应用程序定义或对象定义的错误。
理想情况下,我们可以消除错误并删除重复的行。任何帮助,将不胜感激!谢谢!
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
此外,我也尝试了这段代码,并得到了相同的错误。
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
答案 0 :(得分:1)
rng.RemoveDuplicates Columns:=Array(1), Header:=xlYes
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-removeduplicates-method-excel
Columns:包含重复项的列的索引数组 信息。