代码如下,如果要扩展的话,目前没有什么想法,不过要是知道总共有多少级的话,程序还是可以一次写好的。- Sub 汇总()
- Dim arr, brr(), m#, mm#, n#, i%, j%
- Dim m3#, mm3#, mm2#, m2#
- arr = [a1].CurrentRegion
- For j = UBound(arr) To 1 Step -1
- If arr(j, UBound(arr, 2)) = "四级科目" Then
- m = m + arr(j, 5): mm = mm + arr(j, 6)
- ElseIf arr(j, UBound(arr, 2)) = "三级科目" Then
- arr(j, 5) = m: arr(j, 6) = mm
- m3 = m3 + m: mm3 = mm3 + mm
- m = 0: mm = 0
- ElseIf arr(j, UBound(arr, 2)) = "二级科目" Then
- arr(j, 5) = m3: arr(j, 6) = mm3
- m2 = m2 + m3: mm2 = mm2 + mm3
- ElseIf arr(j, UBound(arr, 2)) = "一级科目" Then
- arr(j, 5) = m2: arr(j, 6) = mm2
- End If
- Next j
- Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
- End Sub
复制代码
|