Proper syntax for summing over intersection of named ranges

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,535
Office Version
  1. 365
Platform
  1. Windows
In the table below, the following named ranges are defined:
$A:$ATableLeft
$E:$ETableRight
$1:$1Jan
$2:$2Feb
$3:$3Mar

<tbody>
</tbody>

I need a formula in E1 that will be the equivalent of =sum(B1:D1) but using the named ranges.

R/CABCDE
1Jan37414
2Feb65617
3Mar4138

<tbody>
</tbody>

I've tried as many combinations of row(), column(), address(), cell(), etc., as I can think of, but mostly I get errors.

I know I can accomplish this sum by naming B1:D1 something like "JanRow" and then using "=sum(JanRow)", but I like having the column named refer to the columns just to the left and right of the table so that they move if I add columns. But regardless of alternative solutions, I'd like to know how to do this.
 
A better version - works with either text or dates (numbers) in TableLeft

=SUM((Jan TableLeft) : (Jan TableRight))-(Jan TableRight) -N(Jan TableLeft)

M.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Because if col A was a date, it would be added to the sum.

Not using Rory's solution. I really don't want to use any solution that depends on Excel excluding text from a sum. I find that error prone. I posted this question because I wanted a way to sum over the data only. Rory gave me exactly that.

If col A contains text, I would do that like this:

tbl refers to: =INDEX(Sheet1!$1:$1048576, ROW(Sheet1!$A$1) + 1, COLUMN(Sheet1!$A$1) + 1):INDEX(Sheet1!$1:$1048576, MATCH(conZzz, Sheet1!$A:$A), COLUMN(Sheet1!$E$1) - 1)

Select some cell in row 1 and define myRow refers to: =1:1 (no $ signs)

ConZzz refers to: =REPT("z", 255) (in all my workbooks)

That definition allows inserting columns left of B, left of E, above row 2, and at the bottom (and, of course, the interior). Then

A​
B
C
D​
E​
F​
1
Month
Val1
Val2
Val3
Total
2
Jan
3​
7
4​
14​
E2: =SUM(tbl myRow)
3
Feb
6​
5​
6​
17​
4​
Mar
4​
1​
3​
8​
5
13
13
13​
B5: =SUM(tbl myCol)

<tbody>
</tbody>

I'd have to study this to understand it, which I would do except I already have a solution that does exactly what I want and it does not extend the sum beyond the boundaries of the table.

But thanks for your effort.
 
Upvote 0
Maybe

=SUM(INDIRECT(CELL("address",OFFSET(TableLeft,0,1) Jan)&":"&CELL("address",OFFSET(TableRight,0,-1) Jan)))


Is this better is some way than Rory's solution?

Code:
=SUM(OFFSET(TableLeft,,1):OFFSET(TableRight,,-1) Jan)

This is simple, I understand it, and, best of all, it works!
 
Upvote 0
oops...

Disregard my previous post

Maybe...
=SUM((TableLeft Jan) : (TableRight Jan))-(Jan TableRight)

Assumes col 1 (TableLeft) as text.
If not try:
=SUM((TableLeft Jan) : (TableRight Jan))-(Jan TableRight)-(Jan TableLeft)

M.

Again,this appears to extend the sum beyond the boundaries of the table itself, which I would prefer not to do. Rory's solution works well and I understand it. But thanks.

PS: Are you related to Castelo Branco, who was president of Brazil back in the 60s?
 
Upvote 0
In particular I don't much like the named ranges for the rows (Jan, Feb etc) since your total formula for each row would need to be entered separately.
In addition, I think that you can achieve what you want (that is, have your sum work even if you insert columns just after the first column or just before the total column) without any named ranges or using any of the volatile functions like OFFSET or INDIRECT.

This formula can be just copied down.


Book1
ABCDE
1Jan37414
2Feb65617
3Mar4138
Self-Adjusting Sum
Cell Formulas
RangeFormula
E1=SUM(INDEX(1:1,COLUMN(A1)+1):INDEX(1:1,COLUMN()-1))
 
Last edited:
Upvote 0
Is this better is some way than Rory's solution?
No. I put it together in response to this:

...I think I tried some version of Offset, but when it returned a numeric, instead of an alpha, value for a column, I didn't think it would work.
The only practical use is that you can see what exactly is summed:

=CELL("address",OFFSET(TableLeft,0,1) Jan)&":"&CELL("address",OFFSET(TableRight,0,-1) Jan)
 
Upvote 0
In particular I don't much like the named ranges for the rows (Jan, Feb etc) since your total formula for each row would need to be entered separately...
Here is a "draggable" formula:

=SUM(OFFSET(TableLeft,,1):OFFSET(TableRight,,-1) INDIRECT(A1))
 
Upvote 0
Again,this appears to extend the sum beyond the boundaries of the table itself, which I would prefer not to do. Rory's solution works well and I understand it. But thanks.

I don't think so. The formula doesn't add any value out of the table boundaries. See post 11

PS: Are you related to Castelo Branco, who was president of Brazil back in the 60s?

Yes, but not close.

M.
 
Last edited:
Upvote 0
Here is a "draggable" formula:

=SUM(OFFSET(TableLeft,,1):OFFSET(TableRight,,-1) INDIRECT(A1))
True, but includes yet another volatile function so not one I'd choose when there's a reasonably straight-forward non-volatile option. :)
.. and what a pain in the neck to set up all the named ranges! :eek:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

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