- Sub zz()
- Dim d, d1, ar, br, cr, dr, m%
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- ar = Sheet12.Range("A3").CurrentRegion
- br = Sheet2.Range("A3").CurrentRegion
- cr = Sheet6.Range("A3").CurrentRegion
- Sheet1.Range("A2:L500").ClearContents
- dr = Sheet1.Range("A1:L500"): m = 1
- For i = 4 To UBound(ar)
- For j = 5 To 11
- d1(ar(i, 3) & "," & ar(i, 4)) = ""
- d(ar(i, 3) & ar(i, 4) & ar(3, j)) = d(ar(i, 3) & ar(i, 4) & ar(3, j)) + ar(i, j)
- Next
- Next
- For i = 4 To UBound(br)
- For j = 5 To 11
- d1(br(i, 3) & "," & br(i, 4)) = ""
- d(br(i, 3) & br(i, 4) & br(3, j)) = d(br(i, 3) & br(i, 4) & br(3, j)) + br(i, j)
- Next
- Next
- For i = 4 To UBound(cr)
- For j = 5 To 11
- d1(cr(i, 3) & "," & cr(i, 4)) = ""
- d(cr(i, 3) & cr(i, 4) & cr(3, j)) = d(cr(i, 3) & cr(i, 4) & cr(3, j)) - cr(i, j)
- Next
- Next
- For Each k In d1.keys
- a = Split(k, ","): m = m + 1
- dr(m, 1) = m - 1: dr(m, 2) = a(0): dr(m, 3) = a(1)
- For j = 4 To UBound(dr, 2) - 2
- dr(m, j) = d(dr(m, 2) & dr(m, 3) & dr(1, j))
- dr(m, 11) = dr(m, 11) + dr(m, j)
- Next
- Next
- Sheet1.Range("A1").Resize(m, UBound(dr, 2)) = dr
- End Sub
复制代码 |