|
这样行不?
- Sub Test()
- Dim Dic As Object, i&, j&, mRow&, Arr, x%
- Dim Fa, Fb
- Set Dic = CreateObject("scripting.dictionary")
- With Sheet1
- mRow = .Cells(.Rows.Count, "D").End(3).Row
- Arr = .[d7].Resize(mRow - 5, 14) '多读一空行,以备识别结束范围
- '分组
- Fa = Format(Arr(1, 1), "0.000")
- For i = 2 To UBound(Arr, 1)
- If Format(Arr(i, 1), "0.000") <> Format(Arr(i - 1, 3), "0.000") Then
- Fb = Format(Arr(i - 1, 3), "0.000")
- k = i - 1
- For k = i - 1 To 1 Step -1
- Arr(k, 5) = Fa & "~" & Fb '组别
- If Format(Arr(k, 1), "0.000") = Fa Then Exit For
- Next k
- Fa = Format(Arr(i, 1), "0.000")
- End If
- Next i
- '求和
- For i = 1 To UBound(Arr, 1)
- If Dic.exists(Arr(i, 5)) Then
- Dic(Arr(i, 5)) = Dic(Arr(i, 5)) & Chr(10) & i
- Else
- Dic(Arr(i, 5)) = i
- End If
- Next i
- ReDim Brr(1 To Dic.Count, 1 To 14)
- x = 0
- For Each k In Dic.keys
- Trr = Split(Dic(k), Chr(10))
- x = x + 1
- For j = 1 To 4
- Brr(x, j) = Arr(Val(Trr(0)), j)
- Next j
- For j = 6 To UBound(Arr, 2)
- tmp = 0
- For i = 0 To UBound(Trr)
- hs = Val(Trr(i))
- tmp = tmp + Arr(hs, j)
- Next i
- Brr(x, j) = tmp
- Next j
- Next k
- End With
- With Sheet2
- mRow = .UsedRange.Rows.Count
- If mRow > 6 Then .Rows("7:" & mRow).ClearContents
- .[d7].Resize(UBound(Brr, 1), UBound(Brr, 2)) = Brr
- End With
- End Sub
复制代码
|
评分
-
2
查看全部评分
-
|