Simple way to remove blank cells dynamic dropdown list Excel - 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

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

How to make an INDIRECT formula but with adjusting ranges

I'm hoping someone can help me make better use of the INDIRECT formula.
I have a list of sheet names in a table and an INDIRECT formula that uses that list to return a value in a specified cell - the list of sheet names is just an easier way for me to drag the formula down the table and read the appropriate cells without having to manually link each sheet.
=INDIRECT("'"&A2&"'!"&"K10")
This works fine for single cells as the range ref is simply stated as the text in the formula (K10), the problem arises when I need to start referring to a range such as K10:K15 and summing the values.
The range K10:K15 will inevitably have new rows added or deleted on the relative tab and as INDIRECT is using text as the reference it means the range doesn't automatically adjust - this is as I understand it one of the 'benefits' of INDIRECT but in this case is actually holding me back.
Also worth noting that the range (K10:K15) may move as rows are added/deleted above this, as this range is part of a larger table.
In simplistic terms I want to achieve the same result as a standard reference to a range on another sheet, e.g. =sum(sheet1!K10:K15) (as this will adjust when rows are added/deleted) but I just want to be able to dictate which sheet is referred to via a list I have in a table on a summary sheet.
How do I either write INDIRECT so the range adjusts when new rows are added/deleted or is there a different formula I should be using that achieves this?
Any advice greatly appreciated :)
=INDIRECT("'"&A2&"'!K"& MATCH(TRUE,INDIRECT("'"&A2&"'!K:K")<>"",0)&":K"&MAX((INDIRECT("'"&A2&"'!K:K")<>"")*(ROW(INDIRECT("'"&A2&"'!K:K")))))
This indirectly references the rows from the first non empty cell up to the last non empty cell in given sheet in column K. Not sure if you need to enter with ctrl + shift + enter (not in the app version).
Note: If the range contains empty cells in between the first and last non empty cell it will be included as value 0
Or in office 365 use the following:
=FILTER(INDIRECT("'"&A2&"'!K:K"),INDIRECT("'"&A2&"'!K:K")<>"")

Auto-Extend Formula Range

I have the following formula:
=IF(MAX(C2:F2)>0,COUNTIF(C2:F2,">1")/COUNT(C2:F2),0)
This formula is located in the second column of a structured table, and goes through the rest of the columns in the table to the right. The formula basically tells how many instances satisfy a certain criteria and puts it in a fraction over the total number of instances. So if the criteria is met 2 times and there were 3 instances I get 2/3 as the output.
I have been researching for an hour now and I can't figure it out. Is there a way to get the cell range in the formula to auto-expand when a new column is added?
You should take advantage of Structured Referencing and Index to get the parts of the table you need
=IFERROR( COUNTIF(
INDEX(YourTableName[#],1,(COLUMN([#FormulaColumn])-COLUMN(YourTableName[#])+2)):
INDEX(YourTableName[#],1,COLUMNS(YourTableName[#])),
">1") /
COUNT(
INDEX(YourTableName[#],1,(COLUMN([#FormulaColumn])-COLUMN(YourTableName[#])+2)):
INDEX(YourTableName[#],1,COLUMNS(YourTableName[#])))
,0)
This will count number of cell to the right of the Formula Column that are >1 and divide that by the count of cells to the right of the Formula Column that are not blank.
The key point here is COLUMNS(YourTableName[#]). This will increase automatically as you add columns
Note: if you want to include blanks in the divisor count, the formula can be adjusted to suit
Just change YourTableName and FormulaColumn to suit your data
From what I can make of the data, the problem can be solved by creating a named range that refers to:
=OFFSET($C$2,0,0,1, COLUMNS(myTable))
The change to the formula is:
=IF(MAX(myRange)>0,COUNTIF(myRange,">1")/COUNT(myRANGE),0)
Where myTABLE is the name of your table and
Where myRANGE is the name of the new named range
How it works:
The named range counts the number of columns in the table and updates whenever one is added it removed. Offset anchors to the left side of the table and extends to the right by the number of columns in the table. The formula drops the cell reference in favor of the named range for improved legibility. It can be copied dragged pasted and moved all over the place and still point to the correct range. With adequate scope, you could put it anywhere in the workbook without issue.
Note: My biggest pet peeve about this method comes when copying the sheet to a a new workbook. Named ranges are so awesome that a workbook scoped range will point to the original workbook even after it has been copied to a new workbook. Sometimes that's a good thing, but us mostly it's a nuisance.
I believe an alternative answer will compliment the first answer because there are innumerable occasions where one may want a dynamic range and simultaneously not want a table.
And that's the clue, for more information you can search for dynamic range. Or more specifically: dynamic named range.
To answer your question:
Yes, it is possible and it's also very handy. For example, the print area can expand and contract with your data and it's very easy to interact with because you work with by name rather than address. And when using VBA, I find it's generally easier to work there named range than a table, that is, unless the table is bound to a variable, in that case they would be equal in my eye. There is just something a fundamentally loathe about typing listobject("table name").listcolum("table colum name").datapropertyrange I almost have a visceral reaction when I have to type it.
The gist of it creating a dynamic named range is simple. Open the name editor, name a range, and use offset() and counta() to define your range. Counting non-empty cells pulls double duty. it is the trigger to recalculate the range and it provides an index that can be used with offset to change the range area.
Here is one example: =OFFSET($A$1,0,0,COUNTA($A:$A),1)
It is very straight forward. With one exception, print range.
For whatever reason, print range doesn't behave the same way and doesn't update like a normal named range. To make it dynamic you create a named range like you normally would. This will be your print range so make it count. Then make your print range refer to that named range. That's all there is to it. The first named range points to the area you want to print and the print at range points to that named range.

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

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)

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.

Resources