我有这个代码的问题:除去列有重复的数据在Excel
Sub text()
Dim iListCount As Integer
Dim x As Variant
Dim iCtr As Integer
' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False
' Get count of records to search through (list that will be deleted).
iListCount = Sheets("sheet2").Cells(Rows.Count, "C").End(xlUp).Row
' Loop through the "master" list.
For Each x In Sheets("Sheet2").Range("A1:A" & Sheets("Sheet2").Cells(Rows.Count, "C").End(xlUp).Row)
' Loop through all records in the second list.
For iCtr = iListCount To 1 Step -1
' Do comparison of next record.
' To specify a different column, change 1 to the column number.
If x.Value = Sheets("Sheet2").Cells(iCtr, 3).Value Then
' If match is true then delete row.
Sheets("Sheet2").Cells(iCtr, 1).EntireRow.Delete
End If
Next iCtr
Next
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub
它运行,而这类作品的。它删除一个重复,但留下所有其他重复。我正在测试这个,所以我使用了一个小样本大小,所以我知道有5个重复项,但是我无法得到这个代码来将它们全部删除。有任何想法吗?我认为它的问题与循环,但不管我改变,我不能让它的工作
你的数据集在excel中看起来像什么? – CBRF23
您正在比较列A和列C并寻找重复的是你想要的?例如x.value是A1和细胞(ICTR,3)是C1 – 99moorem
所以你正在试图除去其中的列C的值在列A中的某处发生的所有行? –