Looking to make a dynamic dropdown list in a table. The photo link below should help visualize the problem.
What I am looking to do is create a dynamic dropdown list in one table using a column from the same table and two columns from a second table in another sheet.
The column with the dropdown should compare the column to the left of it to right column of the second table. The options in the dropdown should be the values in the left column of the second table if the cell to the left of the dropdown cell equals the cell to the right of the value cell in the second table.|
The photo below shows the table setups and the numbers next to the top left table show what options that should be in the dropdown.
Edit: I was looking to do this without using Visual Basic, but I would be open to it if it were the only option.
This is called dependent data validation. You need to set up range names. One for each reference, and an additional one to resolve the reference into a dropdown using Indirect. I set up these four range names and for the data validation I used List > =MyDropdown
a =Sheet1!$H$2:$H$5
b =Sheet1!$H$6:$H$8
cc =Sheet1!$H$9
MyDropdown =INDIRECT(Sheet1!$A2)
Note that the reference inside the INDIRECT() function is relative to the cell that was active when the reference is defined. Select cell in row 2, then create a new named range with that formula. If you select another cell, this will not work.
Note also that the named range cannot be called 'c', so I had to use another reference name.
As per above data setup put below formula to H6
=TRANSPOSE(UNIQUE(E6:E13))
Then put below formula to H7 cell and drag across right.
=FILTER($D$6:$D$13,$E$6:$E$13=H$6)
Above formulas will spill data automatically. Then in data validation for range A1:A10 put below formula
=H$6$#
# after H$6$ will take data dynamically output by Unique() formula till last data.
Then for range B2:B10 data validation formula will
=INDEX($H$7:$J$10,,MATCH($A1,$H$6#,0))
Dropdown result
Related
Can someone help me write VBA function to get data from another worksheet using multiple filter?
Data looks something like this.
I want to write a function that extract the A1 or A2 or A3 value based on the dropdown I select. If I select A3 it should pick data from A3 column. My Filter criteria on other columns are Item, id and location. Column for Item, id and location are static. While column for A1, A2, A3 are dynamic. I want to put criteria on Ite, id and location. These are the three criteria and result should be from the fourth column. i.e. either A1 or A2 or A3 based on what I select.
I tried but couldn't figure out. Can someone help me on this, please?
You don't need VBA for this but you do need to make a few preparations. I will show here what I did. There are other ways and you can choose the way you prefer.
I created a table exactly as you posted. Instead of a table you can just create a named range or you can replace the names of either in the formulas with the range's coordinates. I didn't name the table but recommend that you do if you use a table. In my example the table's name is Table1.
Within the table I created a named range comprising the cells D1:F1. I called this range "Data" but any other name will do as well. You may also move the named range entirely elsewhere if you want different captions for the columns for one reason or another. As you will see, the names are insignificant they are used to create the numbers 1, 2 and 3 from the location where they are within the named range Data.
Now I created a validation drop-down referring to a List of =Data. The effect is that I have a drop-down with A1, A2 and A3 in it. I created this drop-down in A10 of a different sheet from the one on which I have Table1.
Now I used the following formulas to extract data from row 2 of the table.
=INDEX(Table1[Item],2)
=INDEX(Table1[Location],2) or =INDEX(Table1,2,3) and
=INDEX(Table1,2,3+MATCH(A10,Data,0))
Observe that every "2" in the above formulas refers to the 2nd row in the named range Table1. I didn't set up a range of that name but that is something Excel threw in when I created the table. However, you would like to pull data from other rows as well.
For that purpose you can use the ROW() function. This function returns the number of the row in which it resides. If it's in row 10 it will return 10, in row 11 it returns 11 etc. It's a counter. Therefore, if you entered my formulas in row 10 you can replace all the "2"s with Row()-8 and as you copy up or down you will get data from different rows, same columns.
=INDEX(Table1[Item],Row()-8)
=INDEX(Table1[Location],Row()-8) or =INDEX(Table1,Row()-8,3) and
=INDEX(Table1,Row()-8,3+MATCH(A10,Data,0))
If your first formula isn't in row 10 you must adjust the number to be deducted according to where your formula was entered.
I have the following table:
Is there a way to have dynamic drop-down list including all values from only same cluster (example of possible values in Link list column)? Cluster column is big so I am looking for dynamic solution.
So you can do this with formulas, but it's a bit involved. Bottom line is that here is the result I came up with:
The drop-down was created dynamically using dynamic named ranges and formulas
We need to start out with some definitions. This is my test worksheet and data:
The formulas will work out using the named ranges, so you can put your "working area" (the boxed area in green) almost anywhere, including on a different (possibly hidden) worksheet.
You must define four, dynamic named ranges as follows, which match the color-shaded areas in the image above:
Many of these formulas are array formulas, so you must be careful to enter them with CTRL+SHIFT+ENTER.
Once your data areas and names are defined, the first area to populate is the UniqueClusterList (the range on the sheet is F2:M2). We're building a list of unique items, based on the data in your column of cluster values. So you need an array formula that identifies all the unique values in the range. In each cell in the range, enter the array formula CTRL+SHIFT+ENTER for each:
Cell F2 =IFERROR(LOOKUP(2,1/(COUNTIF($E$2:E2,ClusterList)=0),ClusterList),"")
Cell G2 =IFERROR(LOOKUP(2,1/(COUNTIF($E$2:F2,ClusterList)=0),ClusterList),"")
Cell H2 =IFERROR(LOOKUP(2,1/(COUNTIF($E$2:G2,ClusterList)=0),ClusterList),"")
Cell I2 =IFERROR(LOOKUP(2,1/(COUNTIF($E$2:H2,ClusterList)=0),ClusterList),"")
... and so on. Notice that only the cell address in the middle is changing.
Next, we need to build up the list of IDs for each unique Cluster value. This is also an array formula. Starting in cell F3 with CTRL+SHIFT+ENTER:
=IFERROR(INDEX(IDList, SMALL(IF(F$2=ClusterList, ROW(IDList)-2,""), ROW()-2)),"")
Then use your cursor to grab the auto-fill icon in the selection box of that cell and drag it down to cell F16. Since cells F3:F16 are now selected, re-grab the auto-fill icon and drag to the right to fill the whole range F2:M16. All of the values should pop-in as calculated by the formulas.
Your final step is to create the lookup formula for the drop-down list. So select cell C3, then on the ribbon click Data --> Data Tools --> Data Validation to get the dialog window. Now select Allow: List, and in the Source: field enter the following formula:
=OFFSET($F$2,1,MATCH(A3,UniqueClusterList,0)-1,SUMPRODUCT(COUNTIF(IDList,OFFSET($F$2,0,MATCH(A3,UniqueClusterList,0)-1,MAXUNIQUE,1))),1)
You'll now have a drop-down in cell C3 that matches the very first image above. Drag the auto-fill selection icon all the way down to cell C20 and all of those cells will correctly calculate the drop-down list based on the available Clusters and IDs.
How to create a drop down list to select values that with a specific input.
For example, if I have a table below.
And then, I would like to have a drop down list to select dates by the name. Like the one below.
I feel like it can be done by using array formula and if function, something like IF(A2:A7=A,B2:B7). It seems array formula cannot be used in a drop down list.
Thanks!
Few steps involved but not to hard:
Sorted column A
Create new named range, e.g.: DropList`
=INDEX(Sheet1!$B:$B,MATCH(Sheet1!$D$2,Sheet1!$A:$A,0)):INDEX(Sheet1!$B:$B,MATCH(Sheet1!$D$2,Sheet1!$A:$A;0)+COUNTIF(Sheet1!$A:$A,Sheet1!$D$2)-1)
Insert your dropdown validation list and reference the named range
=DropList
Unsorted column A
You'll need a helper column for this.
In cell H1 create a formula:
=IFERROR(AGGREGATE(15,3,($A$2:$A$7=$D$2)*($B$2:$B$7),COUNTIF($A$2:$A$7,"<>"&$D$2)+ROW()),"")
Drag the formula down to H7
Go to name manager and create a new named range, e.g.: DropList
=Sheet1!$H$1:INDEX(Sheet1!$H:$H,COUNTA(Sheet1!$H:$H))
Insert your dropdown validation list and reference the named range
=DropList
Confirm
=INDIRECT(ADDRESS(MATCH(D2,A1:A7,0),2)&":"&ADDRESS(MATCH(D2,A1:A7,0)+COUNTIF(A1:A7,D2)-1,2))
This should work, assuming the data is sorted by name. ADDRESS(MATCH(D1,A1:A7,0)+1,2), add that to the number of rows used in heading, in this case 1, this should return the address of the first cell of the data, column '2' refers to the column in which data is and it should return "$B$2", then in the second part of the formula we calculate the number of 'A' in the data using COUNTIF and add it to the first cell of the variable, similar to the 1st formula we give column as 2.
Then we use Indirect function to convert the strings to address which the data validation can use. And i guess you already know how to use Lists in data validation.
Alternatively, you can keep the address part in one cell, either hide the column or colour text white and protect the cell, and the refer as indirect from the Lists in data validation.
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)
I am making a series of cascading dropdowns in Excel. When a user selects an option in ColumnB, the sheet finds a list "Name"d = ColumnB value and set the validation for that column with that list.
It is working fine
But when I drag the cell in the whole column and try applying the Data Validation property to all cells, instead of selecting the previous cells respectively, it is defining every Data Validation property with the specific cell with which the first cell was binded.
It is not much of a problem as I can do that for individual cell, but I will be setting the data and names through code later, so I need to find a way that every Data Validation source contains a reference to its previous cell instead of that one specific cell.
Remove the $ sign. $ sign means that the reference is absolute and the cell reference in the formulas won't change when the cell is dragged or copied.
Another solution is to define the data validation for the entire column and you don't have to drag anymore.