How do I sum a varying amount of rows based on a user input?

mohr96

New Member
Joined
Jun 22, 2016
Messages
34
Hello,

I am trying to figure out a way to sum a varying amount of rows in excel based on a user input. I will post the images of my spreadsheet below to allow for a better visual representation. In the far left column, are values from 1 to 20. You will then notice in the near left column, the "Properties" column and another three values, just to the right of it. The second row and near right column of the table counts the total number of values that have been placed in the far left column, obviously it is currently 20 values that I have called "conditions". The third row and near right column number, is used as a user input. In this case the user wants the total number of conditions consolidated down to five total conditions. Finally, the fourth row and near right column number calculates the total number of conditions that need to be placed into "bins", a simple division calculation (total conditions/new conditions). So, depending on what the number that the fourth row and near right column contains, will be the amount of conditions that are summed together.

For both tables that I have placed below, assume the top row, far left column is cell A1. For the first table below, because the number of conditions per bin is four, I need four rows per summation. In this case, I would need sum(A2:A5), sum(A6:A9), sum(A10:A13), sum(A14:A17), and sum(A18:A21) to be performed. I have also highlighted the numbers that will correspond to each bin in different colors to allow for a better understanding.
#PropertiesNew Sum
1Total Conditions20=?
2New amount of conditions5=?
3Number of conditions per bin4=?
4=?
5


6


7


8


9


10


11


12


13


14


15


16


17


18


19


20

<tbody>
</tbody>

In the next table below, the difference is that the user now wants only four conditions, so now there will be five conditions per bin. In this case, sum(A2:A6), sum(A7:A11), sum(A12:A16), and sum(A17:A21) will need to be performed. I have highlighted the values in different colors to represent the summations visually.
#PropertiesNew Sum
1Total Conditions20=?
2New amount of conditions4=?
3Number of conditions per bin5=?
4=?
5


6


7


8


9


10


11


12


13


14


15


16


17


18


19


20

<tbody>
</tbody>

My question is, is there a function or VBA coding out there that would allow me to perform these operations with only the user input. In other words, so that I do not have to manually perform all of those sum functions for each row. Please let me know. Thanks!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try

=SUM(OFFSET($A$2,(ROWS($1:1)-1)*$C$4,0,$C$4,1))

A2 is the first cell to sum
C4 contains the number of cells for each sum (4 in your example)
 
Last edited:
Upvote 0
It works! The only thing I had to change was the $a$2 to $a$1 for the starting point, but otherwise works like a charm. Thank you very much!
 
Upvote 0
You're welcome.

Why would you change A2 to A1 ?

You said the first sum should be =SUM(A2:A5)

Changing A2 to A1 makes it =SUM(A1:A4)
 
Last edited:
Upvote 0
For the graph that I placed in here it would work, but for my workbook that I actually pulled the data from, I needed to change the cell number.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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