如何在Excel中find区分大小写的重复项时删除整行(对于100k条logging或更多)?

这是如何删除Excel中的大小写SENSITIVE(对于10万条logging或更多)重复的后续问题? 。

由于他的代码过程只处理列A的数据,所以如果find区分大小写的重复项,我也想删除整行数据

区分大小写的含义

  1. 情况1
  2. 情况1
  3. 情况1

都是独一无二的logging

你可以使用一个Dictionary来检查二进制的唯一性和变体arrays来加快速度。 要使用字典,您需要包含对Microsoft脚本运行时库的引用

(工具>参考> Microsoft脚本运行时库)

我已经testing了100,000行,平均在我的笔记本电脑0.25秒

 Sub RemoveDuplicateRows() Dim data As Range Set data = ThisWorkbook.Worksheets("Sheet1").UsedRange Dim v As Variant, tags As Variant v = data ReDim tags(1 To UBound(v), 1 To 1) tags(1, 1) = 0 'keep the header Dim dict As Dictionary Set dict = New Dictionary dict.CompareMode = BinaryCompare Dim i As Long For i = LBound(v, 1) To UBound(v, 1) With dict If Not .Exists(v(i, 1)) Then 'v(i,1) comparing the values in the first column tags(i, 1) = i .Add Key:=v(i, 1), Item:=vbNullString End If End With Next i Dim rngTags As Range Set rngTags = data.Columns(data.Columns.count + 1) rngTags.Value = tags Union(data, rngTags).Sort key1:=rngTags, Orientation:=xlTopToBottom, Header:=xlYes Dim count As Long count = rngTags.End(xlDown).Row rngTags.EntireColumn.Delete data.Resize(UBound(v, 1) - count + 1).Offset(count).EntireRow.Delete End Sub 

基于这个问题的精彩答案