Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have a worksheet where I would like to sum a set of values but with different variables:-
For example for Row 2 with a condition of 4 I would like to sum cells B2,C2,D2,E2.
However on Row 3 the condition might be 6 so i would want to sum B3,C3,D3,E3,F3,G3.
Can i use a formula to do this, so it determines what the condition is and sums the relevant number of cells.
Thanks

We need more info before we can help.
What is the condition? Where is it stored? What causes the condition to be set?Please be more specific and we'll see what we can do.

What the heck..I'll take a guess at what you are trying to do and offer this. Let me know if I guessed correctly.
Let's say your data starts in column B and you need to sum a variable number of columns based on the value in column A of the same row. i.e. In your examples, you'd have a 4 in A2 and a 6 in A3.
One way to accomplish what you want is to use Dynamic Named Ranges.
For each row, follow this procedure. My example will be for Row 2. Change the 2 to whatever row(s) you want to this in.
1 - Insert...Name...Define
2 - In the Names field enter a name for the Named Range, such as SumRow2
3 - In the Refers to field, enter =OFFSET($B$2,0,0,1,$A$2)
4 - Click OK
5 - In the cell where you want your sum, put =SUM(SumRow2)
Note: You will get an error in your Sum cell until you actually place a value in A2. This can be fixed with an IF statement if required.This works because the Named Range will adjust it's width based on the value in A2.
Look up the OFFSET function for more details.

Sorry if I was'nt very clear but you were right. That is just perfect for what I need to do.
Thank you very much!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |