我正在使用 vba,我有两张名为“Do Not Call”的工作表,在 A 列中有大约 800,000 行数据。我想使用这些数据检查第二张工作表中名为“Sheet1”的 I 列。如果它找到匹配项,我希望它删除“Sheet1”中的整行。我已经定制了从类似问题中找到的代码:Excel 公式交叉引用 2 张工作表,从一张工作表中删除重复项并运行它,但没有任何反应。我没有收到任何错误,但它不起作用。
这是我目前正在尝试的代码,不知道为什么它不起作用
Option Explicit
Sub CleanDupes()
Dim wsA As Worksheet
Dim wsB As Worksheet
Dim keyColA As String
Dim keyColB As String
Dim rngA As Range
Dim rngB As Range
Dim intRowCounterA As Integer
Dim intRowCounterB As Integer
Dim strValueA As String
keyColA = "A"
keyColB = "I"
intRowCounterA = 1
intRowCounterB = 1
Set wsA = Worksheets("Do Not Call")
Set wsB = Worksheets("Sheet1")
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
Do While Not IsEmpty(wsA.Range(keyColA & intRowCounterA).Value)
Set rngA = wsA.Range(keyColA & intRowCounterA)
strValueA = rngA.Value
If Not dict.Exists(strValueA) Then
dict.Add strValueA, 1
End If
intRowCounterA = intRowCounterA + 1
Loop
intRowCounterB = 1
Do While Not IsEmpty(wsB.Range(keyColB & intRowCounterB).Value)
Set rngB = wsB.Range(keyColB & intRowCounterB)
If dict.Exists(rngB.Value) Then
wsB.Rows(intRowCounterB).delete
intRowCounterB = intRowCounterB - 1
End If
intRowCounterB = intRowCounterB + 1
Loop
End Sub
如果上述代码不在代码标签中,我深表歉意。这是我第一次在网上发布代码,我不知道我是否做得正确。