我有需要删除重复项的大型数据集。数据有一个包含ID号的列-我想在此列中循环查找重复的ID。如果存在重复项,我希望代码删除重复项。
我使用的数据集总是具有相同的列-但行数会发生变化,因为我将使用:
Do While Cells(b,4).Value <> "“
然后,在这个循环中,我需要一个If循环来查找重复项并删除它们--怎么做才是最好的呢?
发布于 2020-08-17 23:00:15
正如Scott Craner所提到的,有一个基本的Excel功能可以处理这个问题。
我的Excel工作表如下所示:
Col_D Col_E
1 1
1 1
1 2
1 2
1 3
2 1
2 2
2 2
2 2
2 3记录“数据”选项卡中的“删除重复项”,将生成以下VBA命令:
ActiveSheet.Range("$D$1:$E$11").RemoveDuplicates Columns:=Array(1, 2), Header :=xlYes含义如下:
Range("$D$1:$E$11") : Remove the duplicates from that range
Columns:=Array(1, 2) : Both column 1 (D) and 2 (E) need to be taken into account
(the duplicates of the combination of both columns)
Header :=xlYes : A header row is present结果是:
Col_A Col_B
1 1
1 2
1 3
2 1
2 2
2 3https://stackoverflow.com/questions/63453143
复制相似问题