|
- Sub lqxs()
- Dim DD As New Dictionary
- Dim d1 As New Dictionary
- Dim DD1 As New Dictionary
- Dim d As New Dictionary
- Dim Arr, i&, ks, js, j&, Sht As Worksheet
- Dim k, t, kk, r%, Arr1(), x$, k1, k2
- On Error Resume Next
- Sheet3.Activate
- [a2].Resize(2000, 3).ClearContents
- ks = Val([f1].Value): js = Val([h1].Value)
- For j = ks To js
- Set Sht = Sheets(j)
- Arr = Sht.[a1].CurrentRegion
- For i = 2 To UBound(Arr) - 1
- If Left(Arr(i, 2), 1) <> "[" Then
- DD(Arr(i, 1)) = ""
- If DD.Exists(Arr(i, 1)) Then Set DD(Arr(i, 1)) = New Dictionary: Set DD1(Arr(i, 1)) = New Dictionary
- End If
- Next
- Next
- For j = ks To js
- Set Sht = Sheets(j)
- Arr = Sht.[a1].CurrentRegion
- For i = 2 To UBound(Arr) - 1
- If Left(Arr(i, 2), 1) <> "[" Then
- x = Arr(i, 1) & Arr(i, 2)
- d(x) = d(x) + Arr(i, 10)
- d1(x) = d1(x) + Arr(i, 11)
- Else
- x = " " & Arr(i, 2)
- DD(Arr(i, 1))(x) = DD(Arr(i, 1))(x) + Arr(i, 10)
- DD1(Arr(i, 1))(x) = DD1(Arr(i, 1))(x) + Arr(i, 11)
- End If
- Next
- Next
- k = DD.Keys
- k1 = d.Keys
- For i = 0 To UBound(k)
- r = r + 1
- ReDim Preserve Arr1(1 To 3, 1 To r)
- Arr1(1, r) = k1(i)
- Arr1(2, r) = d(k1(i))
- Arr1(3, r) = d1(k1(i))
- If UBound(DD(k(i))) <> -1 Then
- kk = DD(k(i)).Keys
- For j = 1 To DD(k(i)).Count
- r = r + 1
- ReDim Preserve Arr1(1 To 3, 1 To r)
- Arr1(1, r) = kk(j - 1)
- Arr1(2, r) = DD(k(i))(kk(j - 1))
- Arr1(3, r) = DD1(k(i))(kk(j - 1))
- Next
- End If
- Next
- [a2].Resize(UBound(Arr1, 2), UBound(Arr1)) = Application.Transpose(Arr1)
- Cells(UBound(Arr1, 2) + 2, 1) = "合计"
- Cells(UBound(Arr1, 2) + 2, 2).Formula = "=sum(r2c:r[-1])"
- Cells(UBound(Arr1, 2) + 2, 3).Formula = "=sum(r2c:r[-1])"
- End Sub
复制代码 |
|