|
Sub t()
Dim i, s
i = Sheet1.Cells(Rows.Count, 1).End(3).Row
s = Sheet3.Cells(Rows.Count, 1).End(3).Row
Set d1 = CreateObject("Scripting.Dictionary")
For w = 2 To i
d1(Sheet1.Cells(w, 3)) = Sheet1.Cells(w, 10)
Next w
For a = 2 To s
If d1.exists(Sheet3.Cells(a, 3)) Then Sheet3.Cells(a, 4) = d1(Sheet1.Cells(w, 3))
Next a
Set di = Nothing
End Sub
Sheet1.Cells(w, 10)肯定是有值的,但是不知道为什么d1.exists结果出来都是空值
我的理解是,根据sheet2的A列从sheet1中取值。
另,建议用数组。
- Sub t()
- Dim i, s
- i = Sheet1.Cells(Rows.Count, 1).End(3).Row
- s = Sheet2.Cells(Rows.Count, 1).End(3).Row
- Set d1 = CreateObject("Scripting.Dictionary")
- For w = 2 To i
- d1(Sheet1.Cells(w, 1).Value) = Sheet1.Cells(w, 2)
- Next w
- For a = 2 To s
- Sheet2.Cells(a, 2) = d1(Sheet2.Cells(a, 1).Value)
- Next a
- Set di = Nothing
- End Sub
复制代码
|
|