Excel VBA:如何在Vlookup的两个工作簿之间使用Dictionary?

时间:2017-10-08 16:23:41

标签: excel vba dictionary

我有一个工作表(在我的桌面上),其中包含超过13000行的重复数据,我在另一个位于sharedrive上的文件(名为ProductList)中添加了3个带有vlookup的新列。我试图使用Dictionary但我不知道如何在代码中添加不同的工作簿?我将ProductList作为Sheet2添加到我的文件中,并成功运行代码。

Sub ckv()

Dim Rng As Range, Dn As Range, n As Long, Tic As Object, ray As Variant

'This is normally my ProductList workbook, which has 4 columns

With Sheets("Sheet2")
ray = .Range("A1").CurrentRegion.Resize(, 4)
End With

Set Tic = CreateObject("scripting.dictionary")
Tic.CompareMode = vbTextCompare

For n = 2 To UBound(ray, 1)
Tic(ray(n, 1)) = n

Next

'And this is my file in my desktop
With Sheets("Sheet1")
Set Rng = .Range(.Range("I2"), .Range("I" & Rows.Count).End(xlUp))

For Each Dn In Rng
If Tic.Exists(Dn.Value) Then

 Dn.Offset(, -2) = ray(Tic(Dn.Value), 2)
 Dn.Offset(, -1) = ray(Tic(Dn.Value), 3)
 Dn.Offset(, 1) = ray(Tic(Dn.Value), 4)

  End If

  Next Dn

  End With

End Sub

问候

0 个答案:

没有答案
相关问题