Running total in Excel to a value, reset the cumulative total, and group?

nick_ops

New Member
Joined
Nov 10, 2021
Messages
1
Office Version
  1. 365
Platform
  1. MacOS
I am looking to group a list of numbers based on their sums to a target value. The database is large and would need to be a scalable solution. For instance, if my target value was 10, this would look like the following:

ItemValueTotalGroup
A4I
B3I
C411I
D3II
E2II
F712II
G1010III
H1212IV

What are the formulas I can do this in the Total and Group columns?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi nick_ops

I used a bit of VBA to do this, below. It does not use numerals but adds in a number count for each group.

VBA Code:
Sub SumNGroup()

Dim RunTot As Integer
Dim TotTar As Integer
Dim ValCount As Integer
Dim OffRow As Integer
Dim RowCount As Integer

With Application
    .ScreenUpdating = False
End With

TotTar = Range("E1").Value ' This cell has the value at which to cut off for the total

For Each i In Range("B2:B9") ' Amend range here or use the line below for selected cells
'For Each i In Selection

If OffRow = 0 Then
OffRow = i.Row
ValCount = ValCount + 1
End If
RunTot = RunTot + i.Value
RowCount = RowCount + 1

If RunTot >= TotTar Then
    i.Offset(0, 1).Value = RunTot
    Range("D" & OffRow).Resize(RowCount, 1).Value = ValCount
    RunTot = 0
    OffRow = 0
    RowCount = 0
End If

Next i

With Application
    .ScreenUpdating = True
End With

End Sub

Below are the results I got when running the above code.

Untitled.png


Steven
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,824
Members
449,050
Latest member
Bradel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top