【发布时间】:2012-04-25 22:15:44
【问题描述】:
我的文档中有 2 张纸(带有电话号码)。如果表 1 中存在该数字,我想从表 2 中删除该行。
我快到了(这是我第一次使用 VBA)。但是谁能帮我完成最后一部分。
Sub CleanList()
Dim stopList As Range, cell1 As Range
Set stopList = Sheet1.Range("A1:A10000")
For Each cell1 In stopList
Dim fullList As Range, cell2 As Range
Set fullList = Sheet2.Range("A2:A10000")
For Each cell2 In fullList
If NumberFix(cell1.Value) = NumberFix(cell2.Value) Then
cell2.EntireRow.Delete
End If
Next cell2
Next cell1
End Sub
Private Function NumberFix(ByVal nr As String) As String
If Not nr.StartsWith("46") Then
nr = "46" + nr
End If
NumberFix = nr
End Function
【问题讨论】:
-
您使用的是哪个版本的 Excel?你能澄清一下“最后一部分需要帮助”吗?您可能想看看ozgrid.com/VBA/RemoveDuplicates.htm,这是从范围中删除重复项的众多解决方案之一。
-
+ 1 @ExternalUse:是的,高级过滤器是删除重复项的最快方法之一