|
版主:遇到用字典从2个不同排列的工作表汇总数据的问题。
从一个表中汇总就会用,多一个增加的指定表就不知道该如何实现的。
请帮忙看一 下。https://club.excelhome.net/thread-1626468-1-1.html
Sub 匹配()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("DATA")
ar = .[a1].CurrentRegion
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = i
End If
Next i
With Sheets("DATA2")
ar = .[a1].CurrentRegion
End With
For i = 2 To UBound(ad)
If Trim(ad(i, 1)) <> "" Then
d(Trim(ad(i, 1))) = i
End If
Next i
With Sheets("ZBTQ")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("c2:e" & rs + 1) = Empty
br = .Range("a1:f" & rs)
For i = 2 To UBound(br)
If Trim(br(i, 2)) <> "" Then
xh = d(Trim(br(i, 2)))
If xh <> "" Then
br(i, 3) = Val(ar(xh, 3))
br(i, 4) = Val(ar(xh, 4))
br(i, 5) = ar(xh, 10)
br(i, 3) = Val(ad(xh, 11)) '报错
br(i, 4) = Val(ad(xh, 3)) '报错
br(i, 5) = ad(xh, 6) '报错
End If
End If
Next i
.Range("a1:f" & rs) = br
End With
MsgBox "ok!"
End Sub
谢谢!
|
|