答案 0 :(得分:2)
如果您的数据从A2
开始,请在C2
使用此公式,然后在C
列中复制/粘贴:
=IF(B2=B1,"",SUMPRODUCT(OFFSET(A2,,,MATCH(TRUE,B3:B$1000<>B2,0))))
答案 1 :(得分:0)
我编写了以下代码,这似乎有效。它希望您选择具有要求和的值的列(不是末尾的任何空格),并根据右侧的列将相关的总计添加到第三列。
Sub MyProc()
Dim inputRange As Range
Set inputRange = Selection
Dim Cell As Range
Dim RunningTotal As Integer
Dim VerticalOffset As Integer
Dim PreviousCellFlag As Integer
PreviousCellFlag = 0
For Each Cell In inputRange
If Cell.Offset(0, 1) <> PreviousCellFlag Then
PreviousCellFlag = Cell.Offset(0, 1)
RunningTotal = 0
VerticalOffset = 0
While Cell.Offset(0, 1) = Cell.Offset(VerticalOffset, 1)
RunningTotal = RunningTotal + Cell.Offset(VerticalOffset, 0).Value
VerticalOffset = VerticalOffset + 1
Wend
Cell.Offset(0, 2) = RunningTotal
Else
Cell.Offset(0, 2) = ""
End If
Next Cell
End Sub