ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Variable reference to add cells (https://www.excelbanter.com/excel-discussion-misc-queries/262855-variable-reference-add-cells.html)

Nick Savage

Variable reference to add cells
 
I want to use a variable to add a number of cell values together:

in the example below cell 'e3' needs to be the sum of cells a1:a2 less the
sum of cells a4:e5 but I need to use the value of cell 'a5' to 'go back' 4
columns so that I can vary the number of columns to count back by changing
the value of a5.

a b c d e
1 10

2 20

3

4 2 2 4 2 2

5 4

Thanks

Jim Thomlinson

Variable reference to add cells
 
If I understand your question correctly this should be close...

=SUM(A1:A2)-SUM(A4:INDEX(4:4, 1, A5+1))
--
HTH...

Jim Thomlinson


"Nick Savage" wrote:

I want to use a variable to add a number of cell values together:

in the example below cell 'e3' needs to be the sum of cells a1:a2 less the
sum of cells a4:e5 but I need to use the value of cell 'a5' to 'go back' 4
columns so that I can vary the number of columns to count back by changing
the value of a5.

a b c d e
1 10

2 20

3

4 2 2 4 2 2

5 4

Thanks


Nick Savage

Variable reference to add cells
 
Thanks Jim, I think I need to explain better:

I need a1:a2 and a4:e4 to be referenced from e3, using the value in a5
(the rows will always be 1 & 2 and 4 but the columns need to be dependent
on the value of a5 so

if a5 was 4 the answer would be 20 (a1:a2) - (a4:e4)

and if a5 was 3 the answer would be 12 (b1:b2) - (b4:e4)

key is to change a5 and have different answers without changing formula

a b c d e
1 10 5

2 20 15

3

4 2 2 2 2 2

5 4




Nick


"Jim Thomlinson" wrote:

If I understand your question correctly this should be close...

=SUM(A1:A2)-SUM(A4:INDEX(4:4, 1, A5+1))
--
HTH...

Jim Thomlinson


"Nick Savage" wrote:

I want to use a variable to add a number of cell values together:

in the example below cell 'e3' needs to be the sum of cells a1:a2 less the
sum of cells a4:e5 but I need to use the value of cell 'a5' to 'go back' 4
columns so that I can vary the number of columns to count back by changing
the value of a5.

a b c d e
1 10 5

2 20 15

3

4 2 2 2 2 2

5 4




Thanks


Jim Thomlinson

Variable reference to add cells
 
=INDEX(A1:E1,1,5-A5)+INDEX(A2:E2,1,5-A5)-SUM(INDEX(A4:E4,1,5-A5):E4)
--
HTH...

Jim Thomlinson


"Nick Savage" wrote:

Thanks Jim, I think I need to explain better:

I need a1:a2 and a4:e4 to be referenced from e3, using the value in a5
(the rows will always be 1 & 2 and 4 but the columns need to be dependent
on the value of a5 so

if a5 was 4 the answer would be 20 (a1:a2) - (a4:e4)

and if a5 was 3 the answer would be 12 (b1:b2) - (b4:e4)

key is to change a5 and have different answers without changing formula

a b c d e
1 10 5

2 20 15

3

4 2 2 2 2 2

5 4




Nick


"Jim Thomlinson" wrote:

If I understand your question correctly this should be close...

=SUM(A1:A2)-SUM(A4:INDEX(4:4, 1, A5+1))
--
HTH...

Jim Thomlinson


"Nick Savage" wrote:

I want to use a variable to add a number of cell values together:

in the example below cell 'e3' needs to be the sum of cells a1:a2 less the
sum of cells a4:e5 but I need to use the value of cell 'a5' to 'go back' 4
columns so that I can vary the number of columns to count back by changing
the value of a5.

a b c d e
1 10 5

2 20 15

3

4 2 2 2 2 2

5 4




Thanks


Nick Savage

Variable reference to add cells
 
Wow!!

Cheers Jim, a great help
--
Nick


"Jim Thomlinson" wrote:

=INDEX(A1:E1,1,5-A5)+INDEX(A2:E2,1,5-A5)-SUM(INDEX(A4:E4,1,5-A5):E4)
--
HTH...

Jim Thomlinson


"Nick Savage" wrote:

Thanks Jim, I think I need to explain better:

I need a1:a2 and a4:e4 to be referenced from e3, using the value in a5
(the rows will always be 1 & 2 and 4 but the columns need to be dependent
on the value of a5 so

if a5 was 4 the answer would be 20 (a1:a2) - (a4:e4)

and if a5 was 3 the answer would be 12 (b1:b2) - (b4:e4)

key is to change a5 and have different answers without changing formula

a b c d e
1 10 5

2 20 15

3

4 2 2 2 2 2

5 4




Nick


"Jim Thomlinson" wrote:

If I understand your question correctly this should be close...

=SUM(A1:A2)-SUM(A4:INDEX(4:4, 1, A5+1))
--
HTH...

Jim Thomlinson


"Nick Savage" wrote:

I want to use a variable to add a number of cell values together:

in the example below cell 'e3' needs to be the sum of cells a1:a2 less the
sum of cells a4:e5 but I need to use the value of cell 'a5' to 'go back' 4
columns so that I can vary the number of columns to count back by changing
the value of a5.

a b c d e
1 10 5

2 20 15

3

4 2 2 2 2 2

5 4




Thanks



All times are GMT +1. The time now is 08:16 PM.

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