我使用的是vba,我有兩張工作表,一個名爲「Do Not Call」,在A列中有大約800,000行數據。我想用這些數據檢查第二列中的列I,名爲「Sheet1」。如果找到匹配項,我希望它刪除「Sheet1」中的整行。我已經量身定製了我從類似問題中找到的代碼:Excel formula to Cross reference 2 sheets, remove duplicates from one sheet並運行它,但沒有任何反應。我沒有得到任何錯誤,但它不起作用。如何快速刪除兩個excel工作表之間的重複項vba
這是目前我試圖代碼,不知道爲什麼它不工作
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
我道歉,如果上面的代碼是不是在一個代碼標記。這是我第一次在網上發佈代碼,我不知道我是否做得對。
它需要是VBA。我認爲一個vlookup可以使這非常容易,除非你需要反覆這樣做嗎?樂於幫助VBA,只是可能會矯枉過正? – Ross
感謝您的快速響應!我認爲vlookup,但老實說,我不知道它是否能做我想要的。可悲的是我不熟悉這個功能。我需要將其用於其他工作表(僅替換Sheet1而不是不要調用工作表)。如果我計劃與其他幾張紙一起做這件事,我是否應該查看一下vlookup的內容? – MainTank