|
我用exist方法写了一遍,发现运行不了,感谢大神帮忙看一眼。
Sub 对比去重()
Dim i, j%, d1 As Object, d2 As Object, d3 As Object, k%, x, m
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
Set d3 = CreateObject("scripting.dictionary")
For i = 1 To Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
d1(Sheets(1).Range("A1:A" & i)) = ""
Next i
For j = 1 To Sheets(1).Cells(Rows.Count, 2).End(xlUp).Row
If d1.exists(Sheets(1).Cells(j, 2).Value) Then
k = k + 1
Sheets(3).Cells(k + 1, 3).Value = Sheets(1).Cells(j, 2).Value
Else
k = k + 1
Sheets(3).Cells(k + 1, 2).Value = Sheets(1).Cells(j, 2).Value
End If
Next j
For x = 1 To Sheets(1).Cells(Rows.Count, 2).End(xlUp).Row
d2(Sheets(1).Range("B1:B" & x)) = ""
Next x
k = 0
For m = 1 To Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
If d2.exists(Sheets(1).Cells(m, 1).Value) Then
k = k + 1
Sheets(3).Cells(k + 1, 3).Value = Sheets(1).Cells(m, 1).Value
Else
k = k + 1
Sheets(3).Cells(k + 1, 1).Value = Sheets(1).Cells(m, 1).Value
End If
Next m
End Sub
|
|