Do While keyBaseRow <= UBound(keyData, 1)
' すでに合計が計算されたkeyはスキップ
If IsEmpty(keyData(keyBaseRow, 1)) Then
Dim groupSumValue As Long
groupSumValue = rowSum(keyBaseRow)
keyChkRow = keyBaseRow + 1 ' keyBaseRowより次の行から比較を開始
' まず、合計値を計算
Do While keyChkRow <= UBound(keyData, 1)
If keyData(keyBaseRow, 0) = keyData(keyChkRow, 0) Then
groupSumValue = groupSumValue + rowSum(keyChkRow)
End If
keyChkRow = keyChkRow + 1
Loop
' 次に、一致する全ての行に合計値を保存
keyChkRow = keyBaseRow ' keyBaseRowより次の行から比較を開始
Do While keyChkRow <= UBound(keyData, 1)
If keyData(keyBaseRow, 0) = keyData(keyChkRow, 0) Then
keyData(keyChkRow, 1) = groupSumValue
End If
keyChkRow = keyChkRow + 1
Loop
' keyBaseRow行目にも合計値を保存
keyData(keyBaseRow, 1) = groupSumValue
End If
keyBaseRow = keyBaseRow + 1
Loop