Selecting a Specific Column of a Named Range for t

2019-04-06 14:39发布

问题:

I am trying to create a SUMIF function that dynamically adds up values in a specific column of a named range in my Excel sheet.

It is very easy to do this when there is no named range :

The formula picks out all the cells that contain "London" in their name and sums up the expenses related to London.

What I am trying to do is to use a named range called TripsData (A2:B5) and tell the SUMIF function to sum the entries in the column 2 of this range that meet the criterion of having London in their name.

How can I make this work without needing to create a second named range for column 2 and simply by telling Excel to look within the specified column of this named range? Index/Match only return one value so that doesn't work when there are several cells with London in their name.

Thanks for your help!

回答1:

Use INDEX to refer to a specific column in the named range (it can refer to a whole column), like this

=SUMIF(TripsData,"*London*",INDEX(TripsData,,2))


回答2:

You can do that without any named ranges at all, if you turn your data into an Excel Table object. Select any cell in the range or the whole range and click Insert > Table or hit Ctrl-T.

There will be a dialog that asks if your table has headers. Yours does. Now you can reference the table and its columns by their inherent names and build your formula like this:

=SUMIF(Table1[Expense],"*London*",Table1[Cost])

You can rename the table, of course, even after the formula is in place. When you click a cell in the table, there will be a new ribbon for commands that relate to tables only. It's a very powerful tool.

Any formulas, formatting etc. that apply to a whole table column will automatically carry over into new table rows. The table column reference will adjust automatically, too, of course, so you don't have to mess with dynamic range names or re-define what a named range applies to.

Note: the formula uses structured referencing instead of cell addresses. This option can be turned off by clicking File > Options > Formulas > tick or untick "Use table names in formulas"