|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码写了我也就发下,和3楼的思路不同效果一样:
- Sub Ti()
- Dim dic(2) As Object, arr()
- For x = 0 To 2
- Set dic(x) = CreateObject("Scripting.Dictionary")
- Next
- brr = Sheet1.Range("a2").CurrentRegion
- For x = 2 To UBound(brr)
- dic(0)(brr(x, 1)) = brr(x, 2)
- dic(1)(brr(x, 3)) = brr(x, 4)
- Ts = brr(x, 1) & "/" & brr(x, 2) & "/" & brr(x, 3) & "/" & brr(x, 4)
- dic(2)(Ts) = brr(x, 5)
- Next
- ReDim arr(1 To dic(0).Count + 3, 1 To dic(1).Count + 3)
- Ts = dic(0).Keys: T = dic(1).Keys
- For y = 0 To UBound(T)
- arr(1, y + 3) = T(y)
- arr(2, y + 3) = dic(1)(T(y))
- For x = 0 To UBound(Ts)
- If arr(x + 3, 1) = "" Then
- arr(x + 3, 1) = Ts(x)
- arr(x + 3, 2) = dic(0)(Ts(x))
- rr = arr(x + 3, 1) & "/" & arr(x + 3, 2) & "/" & arr(1, y + 3) & "/" & arr(2, y + 3)
- If dic(2).Exists(rr) Then arr(x + 3, y + 3) = dic(2)(rr)
- arr(UBound(arr), y + 3) = arr(UBound(arr), y + 3) + dic(2)(rr)
- Else
- rr = arr(x + 3, 1) & "/" & arr(x + 3, 2) & "/" & arr(1, y + 3) & "/" & arr(2, y + 3)
- If dic(2).Exists(rr) Then arr(x + 3, y + 3) = dic(2)(rr)
- arr(UBound(arr), y + 3) = arr(UBound(arr), y + 3) + dic(2)(rr)
- End If
- arr(x + 3, UBound(arr, 2)) = arr(x + 3, UBound(arr, 2)) + arr(x + 3, y + 3)
- arr(UBound(arr), UBound(arr, 2)) = arr(UBound(arr), UBound(arr, 2)) + arr(x + 3, y + 3)
- Next
- Next
- arr(UBound(arr), 1) = "总计": arr(1, UBound(arr, 2)) = "总计"
- Range("g12").Resize(UBound(arr), UBound(arr, 2)) = arr
- End Sub
复制代码 |
|