ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   Controlling Cells included in a sum command (https://www.excelbanter.com/new-users-excel/447838-controlling-cells-included-sum-command.html)

Jim Schnur

Controlling Cells included in a sum command
 
Hi,

I need to be able to control the cells that are summed by a number in another cell.

My current sum statement is =SUM (L102,T102,X102,AD102,AJ102).

I need to use the value is cell A1 to indicate how many of the summed cells to included.

For instance if A1=1 then cell L102 is included in the sum. If A1=2 then L102 and T102 would be included in the sum.
Any help would be greatly appreciated.

joeu2004[_2_]

Controlling Cells included in a sum command
 
"Jim Schnur" wrote:
I need to be able to control the cells that are summed by a number
in another cell.
My current sum statement is =SUM (L102,T102,X102,AD102,AJ102).
I need to use the value is cell A1 to indicate how many of the
summed cells to included.
For instance if A1=1 then cell L102 is included in the sum.
If A1=2 then L102 and T102 would be included in the sum.


One way....

Create a table in a range, for example:

X1: =L102
X2: =T102
X3: =X102
X4: =AD102
X5: =AJ102

Then the SUM formula can be:

=SUM(X1:INDEX(X1:X5,A1))

Kevin@Radstock

Hi

Maybe using a IF function could be one option: =IF(A1=1,SUM(L102),IF(A1=2,SUM(L102,T102),IF(A1=3, SUM(L102,T102,X102),IF(A1=4,SUM(L102,T102,X102,AD1 02),IF(A1=5,SUM(L102,T102,X102,AD102,AJ102))))))

Quote:

Originally Posted by Jim Schnur (Post 1608050)
Hi,

I need to be able to control the cells that are summed by a number in another cell.

My current sum statement is =SUM (L102,T102,X102,AD102,AJ102).

I need to use the value is cell A1 to indicate how many of the summed cells to included.

For instance if A1=1 then cell L102 is included in the sum. If A1=2 then L102 and T102 would be included in the sum.
Any help would be greatly appreciated.


Jim Schnur

Quote:

Originally Posted by joeu2004[_2_] (Post 1608058)
"Jim Schnur" wrote:
I need to be able to control the cells that are summed by a number
in another cell.
My current sum statement is =SUM (L102,T102,X102,AD102,AJ102).
I need to use the value is cell A1 to indicate how many of the
summed cells to included.
For instance if A1=1 then cell L102 is included in the sum.
If A1=2 then L102 and T102 would be included in the sum.


One way....

Create a table in a range, for example:

X1: =L102
X2: =T102
X3: =X102
X4: =AD102
X5: =AJ102

Then the SUM formula can be:

=SUM(X1:INDEX(X1:X5,A1))

Thank you.......

Jim Schnur

Quote:

Originally Posted by Kevin@Radstock (Post 1608057)
Hi

Maybe using a IF function could be one option: =IF(A1=1,SUM(L102),IF(A1=2,SUM(L102,T102),IF(A1=3, SUM(L102,T102,X102),IF(A1=4,SUM(L102,T102,X102,AD1 02),IF(A1=5,SUM(L102,T102,X102,AD102,AJ102))))))

Thank You... This will work for me Kevin...


All times are GMT +1. The time now is 06:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com