Selecting a Specific Column of a Named Range for the SUMIF Function - excel

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!

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))

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"

You can use Chris' idea of Index(Table1,,Col#) with the named range "Table1" (without creating an Excel table Object if you don't want to for some reason) and STILL avoid the problem Applez mentions in the comment below Chris' idea. Applez warns that using a constant for a column number reference is dangerous if you later insert another column before that column in the named range. You will find that Excel does NOT auto increment the constant, so your formula breaks.
Applez is right..... so DON'T use a constant, use a column number "reference" instead of a constant. For example....
=SUMIF(TripsData,"*London*",INDEX(TripsData,,Column(B1)))
If you later insert a column between A and B, Excel WILL auto increment the reference Column(B1) to Column(C1). Just don't delete B1 or Row 1 or you will get a REF error. I usually use the the header/tile "cell" (in whatever row that is in) for that table column within the Column reference (as it is highly unlikely I will ever delete the header/title cell of column of a table unless I delete the entire column). In this particular example as it turn out, B1 "IS" the the title/header cell for that column in the data table. So that is what I used for the example.

Awesome formula, just in case anyone needs to use a similar approach to FILTER a range. I used this approach
pmGendHC is the range I wanted to filter (I expect a spilled range with my data) I needed a colum (column number 13) to be different than 0
=FILTER(pmGendHC,INDEX(pmGendHC,,13)<>0)

Related

Having trouble with an Excel formula in the data validation window [duplicate]

Whenever I do a dependent dynamic drop down list , I see a bunch of blank cell in the drop-down list , I search many topics that explain how to remove them while by adding two additional ranges like explained her http://blog.contextures.com/archives/2014/02/27/dynamic-list-with-blank-cells/
but my question is: Is there anyway to avoid blank cell or remove them using a simple approach without the need of two additional ranges or a complex formula?
the drop down list that contains blank cell all I did is go to data validation and wrote in source =MYCode then I named the list that contains the codes like that MyCodeand I checked ignore blank case (even tho It seems to be useless )
There is another way. Create a dynamically-expanding named range. Then use the range to define the data validation list.
To create your dynamically-expanding range, insert this in the named range box and give it a name:
=OFFSET($A$1,0,0,COUNTA($A:$A),1)
$A$1 should be replaced with the top cell of your range. $A$A should be replaced with the column(s) the range is in.
OFFSET points the named range at a range of cells. COUNTA() is in the fourth position of the OFFSET formula, which sets the height of the range. It counts the number of non-blank cells. As a result, when you add a value, the fourth value of the OFFSET formula increases and you get an expanding range.
Note, this does not work if your named range has blank cells interspersed.
OFFSET formula from excel-easy.com.
After some more research I found a solution. In the cell where my information is filled I added a name using the name Manager and I added this formula that I adapted from this article:
=DropList!$J$1:INDEX(DropList!$J$1:$J$10000,SUMPRODUCT(--(DropList!$J$1:$J$10000<>"")))
It did what I needed without the need of adding 2 extra cell, even though the line of code is rather complex.
I know this thread is dead but I found a simpler solution which only requires you to create a single named range. It also works even if blank cells are interspersed in the source data, and expands as the source data expands.
First create your dynamically expanding named range using the formula given above:
=OFFSET($A$1,0,0,COUNTA($A:$A),1)
This will includes the values you want in your drop-down, as well as blank cells.
Next, in a separate cell, enter the following:
=FILTER(Your_Range, Your_Range <> "")
The result will be your source data with no blanks. This will spill into adjacent cells. Now can reference this single cell as your data validation list, as long as you add "#" to the end of the cell reference. This tells excel to include all the spilled values in the list.
Benefits:
If your source data named range is dynamic, the drop-down list will expand with this range, and you don't have to worry about updating a second named range.
You can easily filter more data, and it doesn't matter if blank cells are interspersed.
Combined with the SORT and UNIQUE functions, you can further improve how your data is represented in the drop-down list.
I couldn't find a solution this simple anywhere else, so I hope someone finds this useful.
If there are no empty cells within the source list, but the empty rows come from the end of the list, you can get rid of those by using a table as the source of the dropdown. You have to use the INDIRECT function to refer to the table:
Select the whole source list including the header
Click Format as table
Select the table, go to the Design tab (under Table Tools)
Rename the table
Select the cells where you want to use the dropdown and open the Data Validation
As the dropdown source, set: =INDIRECT("TableName[ColumnName]") (note the double-quotes)
This article explains the procedure in more detail

excel link table range to value

I'm searching for a way to link the range of an Excel table to a specific number.
Let's say I have a table that has a range of A1:B10. I want to make the number '10' dynamic and link it to a number that is calculated from another sheet. Let's say cell F1 contains that number and the value is '20'.
Is it possible to make a dynamic range so the table range changes to: A1:B(F1). Then my table would adapt automatically and this has to work in my file.
I prefer a formula instead of a macro in VBA, because I normally don't work with VBA.
An alternative is to use a dynamic named range which is what we used to do before tables. The range, enclosed by marching ants below, is defined as follows:
=OFFSET(Sheet3!$A$1,0,0,Sheet3!$F$1,5)
The top left cell is A1. It is as many rows deep as the number in F1 and 5 columns wide (which could also be made dynamic).
Yes, INDIRECT is your way to make any formula dynamic / dependent on other cell values.
Say you want to sum range A2:C2. But the value 2 for C is located in Cell G2.
=SUM(INDIRECT("A2"&":C"&G2))
this is equal to write =SUM(A2:C2) in my example below.
If you set G2 to 3 it would calculate A2:C3 for this =SUM(INDIRECT("A2"&":C"&G2)).
If you mean Excel table, I guess the answer is no with formula, probably with VBA.

Simple way to remove blank cells dynamic dropdown list Excel

Whenever I do a dependent dynamic drop down list , I see a bunch of blank cell in the drop-down list , I search many topics that explain how to remove them while by adding two additional ranges like explained her http://blog.contextures.com/archives/2014/02/27/dynamic-list-with-blank-cells/
but my question is: Is there anyway to avoid blank cell or remove them using a simple approach without the need of two additional ranges or a complex formula?
the drop down list that contains blank cell all I did is go to data validation and wrote in source =MYCode then I named the list that contains the codes like that MyCodeand I checked ignore blank case (even tho It seems to be useless )
There is another way. Create a dynamically-expanding named range. Then use the range to define the data validation list.
To create your dynamically-expanding range, insert this in the named range box and give it a name:
=OFFSET($A$1,0,0,COUNTA($A:$A),1)
$A$1 should be replaced with the top cell of your range. $A$A should be replaced with the column(s) the range is in.
OFFSET points the named range at a range of cells. COUNTA() is in the fourth position of the OFFSET formula, which sets the height of the range. It counts the number of non-blank cells. As a result, when you add a value, the fourth value of the OFFSET formula increases and you get an expanding range.
Note, this does not work if your named range has blank cells interspersed.
OFFSET formula from excel-easy.com.
After some more research I found a solution. In the cell where my information is filled I added a name using the name Manager and I added this formula that I adapted from this article:
=DropList!$J$1:INDEX(DropList!$J$1:$J$10000,SUMPRODUCT(--(DropList!$J$1:$J$10000<>"")))
It did what I needed without the need of adding 2 extra cell, even though the line of code is rather complex.
I know this thread is dead but I found a simpler solution which only requires you to create a single named range. It also works even if blank cells are interspersed in the source data, and expands as the source data expands.
First create your dynamically expanding named range using the formula given above:
=OFFSET($A$1,0,0,COUNTA($A:$A),1)
This will includes the values you want in your drop-down, as well as blank cells.
Next, in a separate cell, enter the following:
=FILTER(Your_Range, Your_Range <> "")
The result will be your source data with no blanks. This will spill into adjacent cells. Now can reference this single cell as your data validation list, as long as you add "#" to the end of the cell reference. This tells excel to include all the spilled values in the list.
Benefits:
If your source data named range is dynamic, the drop-down list will expand with this range, and you don't have to worry about updating a second named range.
You can easily filter more data, and it doesn't matter if blank cells are interspersed.
Combined with the SORT and UNIQUE functions, you can further improve how your data is represented in the drop-down list.
I couldn't find a solution this simple anywhere else, so I hope someone finds this useful.
If there are no empty cells within the source list, but the empty rows come from the end of the list, you can get rid of those by using a table as the source of the dropdown. You have to use the INDIRECT function to refer to the table:
Select the whole source list including the header
Click Format as table
Select the table, go to the Design tab (under Table Tools)
Rename the table
Select the cells where you want to use the dropdown and open the Data Validation
As the dropdown source, set: =INDIRECT("TableName[ColumnName]") (note the double-quotes)
This article explains the procedure in more detail

Create 100+ Named ranges based on formula in cells

been looking for quite a while now, due lack of distinctive terminology couldn't find any solution, so maybe the experts out here can help.
So I got this table of 300+ collumns that are populated like this
row 1 Header/Name.
row 2 Range formula ment to be in the "Refers to" input area when a "New Name" for a range is created.
row 3/22 The information used in the range formula.
To use the range formula's in a data validation on another sheet I need to Name these ranges. If I manually enter a "New Name" I can copy the range formula from row 2 into the "refers to" input area, only with 300 columns that would be a long day of labor. That's when I found out about the CRTL+SHIFT+F3 combo which makes it possible to create a lot of named ranges at once based on a header/name and selection. Unfortunately this uses the location of selection as the source and in my case it should be the formula inside the locations's cell which would have to be the source...
So is there a way to use the "Create Names From Selection" tool that uses a formula inside a cell as the source instead of the location?
here's an image to help describe the problem
You should be able to solve this problem with 1 named range for every validation (plus 2 additional to make the formula less complicated).
The first named range (all_headers) should be defined as:
=OFFSET('C'!$A$1,0,0,1,COUNTA('C'!$1:$1))
It returns a range with the headers (product names or codes) from the C sheet. We assume that the first column is A and there are no empty columns between them.
Next we need to choose the right column. Here it gets a little tricky. In the row where you want to validate colors, you need to have exactly the same product name or code that is used in the C sheet headers. If this information is in cell A2, you should:
select the cell in the same row and in the column where the color validation is supposed to be (for example B2)
define new named range col_header with the following formula:
=INDEX(all_headers,1,MATCH(A2,all_headers,0))
The above dynamic named range is relative, that's why selecting the proper cell before defining it is very important.
The last step is to define named range val_list with reference to the list of colors from the chosen column:
=OFFSET(col_header,2,0,COUNTA(OFFSET(col_header,2,0,50,1)),1)
You mentioned that the second row does not contain data, that's why there is 2 parameter twice in the formula. If you remove it, use 1 instead. 50 is the maximum number of colors - you can adjust it.
Now you can use val_list for validation in any cell. It should give you the right list if the cell on the left contains a valid product name/code from the C sheet header.

Sum/Count Formulas auto adjust for inserted rows

Looking to create a sum and a count formula that will automatically adjust itself for new rows that are inserted within the range.
For example if I have the formula in cell D55 =SUM(D17:D54). Every time I insert a new row within that range, I need to change the top range of my formula to account for it.
Is there a way to write a formula that will automatically adjust itself, so that every time I add a new row I will not need to change my summation formula?
Try
D55: =SUM(INDIRECT("D17:D"&ROW()-1))
This should dynamically adjust to added rows since when adding rows at row 17 the current value at D17 shifts to D18 and no value is present at D17. INDIRECT() should take this into account. ROW()-1 ensures that even when rows are added immediately preceding the formula these are still taken into account.
Edit: I should have added that this can be applied to any formula. Simply replace the range part of your formula with the INDIRECT.
And a quick explanation: the INDIRECT creates an Excel reference from a string so you can construct your formula using dynamic objects. The ROW part of the formula acts as the dynamic factor which is completely dependent on the row count that you add but is independent of the position at which you add your new row.
I think people are misunderstanding. You're inserting a row at the TOP of your range correct?
If so, I would suggest formatting the range as a table. That way your table could look like this:
And the sum function would be simply:
=SUM([Data])
when a row is inserted above the 7, everything is automatically updated.
You might want to have a look at this excellent link that talks about using tables to hold your ranges. This would be my recommendation ... wrap your data in a table. This will create a structured yet flexible reference.
As is noted here, and also from experience, "Because table data ranges often change, the cell references for structured references adjust automatically. For example, if you use a table name in a formula to count all the data cells in a table, and you then add a row of data, the cell reference automatically adjusts."

Resources