|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
各位老师好,我刚接触字典,平时在论坛中看到大佬们用字典6得飞起,我非常的佩服,也按照论坛的的方法慢慢的学习,现在绞尽脑汁写了一个,但是发现非常的长,我觉得应该不是这样的,应该能更简练,求各位老师指导,我这样写是不是错了?
然后发现有的数据类型不对的,也匹配不了,麻烦各位老师指导一下,感谢!!
具体见附件。
Sub 字典计算()
t = Timer
Dim d As Object, d1 As Object, arr, brr
Set d = CreateObject("scripting.dictionary")
Set d1 = CreateObject("scripting.dictionary")
Set qdgh = Sheets("做字典")
Set xrw = Sheets("第一个")
Set kd = Sheets("第二个")
Set qyb = Sheets("第三个")
arr = qdgh.[a1].CurrentRegion
For i = 1 To UBound(arr)
d(arr(i, 1)) = arr(i, 2)
Next i
For j = 1 To UBound(arr)
d1(arr(j, 1)) = arr(j, 3)
Next j
r = xrw.Cells(Rows.Count, "A").End(3).Row
brr = xrw.Range("A2:A" & r)
For k = 1 To UBound(brr)
brr(k, 1) = d(brr(k, 1))
Next k
xrw.Range("B2:B" & r) = brr
brr = xrw.Range("A2:A" & r)
k = 1
For k = 1 To UBound(brr)
brr(k, 1) = d1(brr(k, 1))
Next k
xrw.Range("C2:C" & r) = brr
r = kd.Cells(Rows.Count, "A").End(3).Row
brr = kd.Range("A2:A" & r)
k = 1
For k = 1 To UBound(brr)
brr(k, 1) = d(brr(k, 1))
Next k
kd.Range("B2:B" & r) = brr
brr = kd.Range("A2:A" & r)
k = 1
For k = 1 To UBound(brr)
brr(k, 1) = d1(brr(k, 1))
Next k
kd.Range("C2:C" & r) = brr
r = qyb.Cells(Rows.Count, "A").End(3).Row
brr = qyb.Range("A2:A" & r)
k = 1
For k = 1 To UBound(brr)
brr(k, 1) = d(brr(k, 1))
Next k
qyb.Range("B2:B" & r) = brr
brr = qyb.Range("A2:A" & r)
k = 1
For k = 1 To UBound(brr)
brr(k, 1) = d1(brr(k, 1))
Next k
qyb.Range("C2:C" & r) = brr
MsgBox "匹配完成:" & Format(Timer - t, "0.000秒")
End Sub
|
|