Excel drop down list combine two columns
Sep 30 Making a dependent (cascading) drop down list in Excelby | updated on July 17, 2021 Show
Last week we started to explore the capabilities of Excel Data Validation and learned how to create a simple drop-down list in Excel based on a comma-separated list, range of cells or a named range. Today, we are going to investigate this feature in-depth and learn how to create cascading drop down lists that display choices depending on the value selected in first dropdown. To put it differently, we will make an Excel data validation list based on the value of another list.
How to create a multiple dependent dropdown in ExcelMaking a dependent drop-down lists in Excel is easy. All you need is a few named ranges and the INDIRECT formula. This method works with all versions of Excel 2019, 2016, 2013, 2010 and earlier. 1. Type the entries for the drop-down lists.First off, type the entries you want to appear in the drop-down lists, each list in a separate column. For example, I'm creating a cascading dropdown of fruit exporters and column A of my source sheet (Fruit) includes the items of the first dropdown and 3 other columns list the items for the dependent dropdowns. 2. Create named ranges.Now you need to create names for your main list and for each of the dependent lists. You can do this either by adding a new name in the Name Manager window (Formulas tab > Name Manager > New) or typing the name directly in the Name Box. Note. Please pay attention that if your first row is sort of column header like you see in the screenshot above, you shall not include it in the named range. For the detailed step-by-step instructions please see Creating a named range. Things to remember:
When done, you may want to press Ctrl+F3 to open the Name Manager window and check if all of the lists have correct names and references. 3. Make the first (main) drop-down list.
4. Create the dependent drop-down list.Select a cell(s) for your dependent drop-down menu and apply Excel Data Validation again as described in the previous step. But this time, instead of the range's name, you enter the following formula in the Source field: =INDIRECT(A2) Where A2 is the cell with your first (primary) drop-down list. If cell A2 is currently empty, you will get the error message "The Source currently evaluates to an error. Do you want to continue?" Safely click Yes, and as soon as you select an item from the first drop-down menu, you will see the entries corresponding to it in the second, dependent, drop-down list. 5. Add a third dependent drop-down list (optional)If needed, you could add a 3rd cascading drop-down list that depends either on the selection in the 2nd drop-down menu or on the selections in the first two dropdowns. Set up a 3rd dropdown that depends on the 2nd listYou can make the drop-down list of this type in the same fashion as we've just made a second dependent drop-down menu. Just remember the 2 important things discussed above, which are essential for the correct work of your cascading drop-down lists. For instance, if you want to display a list of regions in column C depending on which country is selected in column B, you create a list of regions for each country and name it after the country's name, exactly as the country appears in second dropdown lists. For instance, a list of Indian regions should be named "India", a list of Chines regions - "China", and so on. After that, you select a cell for the 3rd dropdown (C2 in our case) and apply Excel Data Validation with the following formula (B2 is the cell with the second drop-down menu that contains a list of countries): =INDIRECT(B2) Now, each time you select India under the list of countries in column B, you will have the following choices in the third drop-down: Note. The displayed list of regions is unique for each country but it does not depend on the selection in the first drop-down list. Create a third dropdown dependent on the first two listsIf you need to create a cascading drop down menu that depends on the selections both in the first and second drop-down lists, then proceed in this way:
This is the easiest way to create cascading drop-down boxes in Excel. However, this method has a number of limitations. Limitations of this approach:
How to create cascading drop-down lists with multi-word entriesThe INDIRECT formulas like we used in the example above can handle one-word items only. For example, the formula =INDIRECT(A2) indirectly references cell A2 and displays the named range exactly with the same name as is in the referenced cell. However, spaces are not allowed in Excel names, which is why this formula won't work with multi-word names. The solution is to use the INDIRECT function in combination with SUBSTITUTE like we did when creating a 3rd dropdown. Suppose you have Water melon among the products. In this case, you name a list of water melon exporters with one word without spaces - Watermelon. Then, for the second dropdown, apply Excel Data Validation with the following formula that removes the spaces from the name in cell A2: =INDIRECT(SUBSTITUTE(A2," ","")) How to prevent changes in the primary drop down listImagine the following scenario. Your user has made the selections in all of the drop-down lists, then they changed their mind, went back to the first list, and chose another item. As the result, the 1st and 2nd selections are mismatched. To prevent this from happening, you may want to block any changes in the first drop-down list as soon as a selection is made in the second list. To do this, when creating the first dropdown, use a special formula that will check whether any entry is selected in the second drop down menu: =IF(B2="", Fruit, INDIRECT("FakeList")) Where B2 contains the second dropdown, "Fruit" is the name of the list that appears in the first drop-down menu, and "FakeList" is any fake name that does not exist. Now, if any item is selected in the 2nd drop-down list, no choices will be available when the user clicks on the arrow next to the first list. Creating dynamic cascading drop-down lists in ExcelThe main advantage of a dynamic Excel dependent drop-down list is that you are free to edit the source lists and your drop-down boxes will get updated on the fly. Of course, creating dynamic dropdowns requires a bit more time and more complex formulas, but I believe this is a worthy investment because once set up, such drop-down menus are real pleasure to work with. As with almost anything in Excel, you can achieve the same result in several ways. In particular, you can create a dynamic dropdown using a combination of OFFSET, INDIRECT and COUNTA functions or a more resilient INDEX / MATCH. The latter is my preferred way because it provides numerous advantages, the most essential of which are:
Okay, enough theory, let's get to practice. 1. Organize your source data in a table.As usual, the first thing for you to do is to write down all the choices for your drop-down lists in a worksheet. This time, you will have store the source data in an Excel table. For this, once you have entered the data, select all of the entries and press Ctrl + T or click Insert tab > Table. Then type a name of your table in the Table Name box. The most convenient and visual approach is to store the items for the first drop-down as table headers, and the items for the dependent dropdown as table data. The screenshot below illustrates the structure of my table, named exporters_tbl - the fruit names are table headers and a list of exporting countries is added under the corresponding fruit name. 2. Create Excel names.Now that your source data is ready, it's time to set up named references that will dynamically retrieve the correct list from your table. 2.1. Add a name for the table's header row (main dropdown)To create a new name that references the table header, select it and then either click Formulas > Name Manager > New or press Ctrl + F3. Microsoft Excel will use the built-in table reference system to create the name of the table_name[#Headers] pattern. Give it some meaningful and easy to remember name, e.g. fruit_list, and click OK. 2.2. Create a name for the cell containing the first drop-down list.I know that you don't have any dropdown yet :) But you have to choose the cell to host your first dropdown and create a name for that cell now because you will need to include this name in the third name's reference. For example, my first drop-down box is reside in cell B1 on Sheet 2, so I create a name for it, something simple and self-explanatory like fruit: Tip. Use appropriate cell references to copy drop-down lists across the worksheet. Please be sure to read the following few paragraphs carefully because this a very useful tip you that don't want to miss. Thanks a lot to Karen for posting it! If you plan to copy your drop-down lists to other cells, then use mixed cell references when creating the name for the cell(s) with your first drop-down list. For the drop-downs to copy correctly to other columns (i.e. to the right), use relative column (without the $ sign) and absolute row (with $) references like = Sheet2!B$1. As the result, B1's dependent drop down list will appear in cell B2; C1's dependent drop-down will display in C2, and so on. And if you plan to copy the dropdowns to other rows (i.e. down the column), then use absolute column (with $) and relative row (without $) coordinates like = Sheet2!$B1. To copy a drop-down cell in any direction, use a relative reference (without the $ sign) like = Sheet2!B1. 2.3. Create a name to retrieve the dependent menu's entries.Instead of setting up unique names for each of the dependent lists like we did in the previous example, we are going to create one named formula that is not assigned to any particular cell or a range of cells. It will retrieve the correct list of entries for the second dropdown depending on which selection is made in the first drop-down list. The main benefit of using this formula is that you won't have to create new names as you add new entries to the first drop-down list - one named formula covers them all. You create a new Excel name in the usual way (Formulas > Name Manager > New) with this formula: =INDEX(exporters_tbl,,MATCH(fruit,fruit_list,0)) Where:
I gave it a name exporters_list, as you see in the screenshot below. If you are curious to learn the Index and Match functions in-depth, check out this tutorial: INDEX & MATCH - a better alternative to VLOOKUP. Well, you have already done the major part of the work! Before getting to the final step, it may be a good idea to open the Name Manager (Ctrl + F3) and verify the names and references: 3. Set up Excel Data ValidationThis is actually the easiest part. With the two named formulas in place, you set up Data Validation in the usual way (Data tab > Data validation).
Done! Your dynamic cascading drop-down menu is accomplished and will update automatically reflecting the changes you've made to the source table. This dynamic Excel dropdown, perfect in all other respects, has one shortcoming - if the columns of your source table contain a different number of items, the blank rows will appear in your menu like this: Exclude blank rows from the dynamic cascading dropdownIf you want to clean any blank lines in your drop-down boxes, you will have to take a step further and improve the INDEX / MATCH formula used to create the dependent dynamic drop-down list. The idea is to use 2 INDEX functions, where the first gets the upper-left cell and the second returns the lower-right cell of the range, or the OFFSET function with nested INDEX and COUNTA. The detailed steps follow below: 1. Create two additional names.Not to make the formula too bulky, create a couple of helper names with the following simple formulas first:
In the above formulas, exporters_tbl is your source table's name, fruit is the name of the cell containing the first dropdown, and fruit_list is the name referencing the table's header row. 2. Create the named reference for the dependent dropdown.Next, utilize either of the below formulas to create a new name (let's call it exporters_list2) to be used with the dependent drop-down list: =INDEX(exporters_tbl,1,col_num) : INDEX(exporters_tbl, COUNTA(entire_col), col_num) =OFFSET(INDEX(exporters_tbl,1,col_num),0,0,COUNTA(entire_col)) 3. Apply Data Validation.Finally, select the cell containing the dependent dropdown and apply Data Validation by entering = exporters_list2 (the name created in the previous step)in the Source box. The screenshot below shows the resulting dynamic drop-down menu in Excel where all blank lines are gone! Note. When working with dynamic cascading drop down lists created with the above formulas, nothing prevents the user from changing the value in the first dropdown after making the selection in the second menu, as a result, the choices in the primary and secondary dropdowns may mismatch. You can block changes in the first box after a selection is made in the second one by using either VBA or complex formulas suggested in this tutorial. This is how you create an Excel data validation list based on the values of another list. Please feel free to download our sample workbooks to see the cascading drop-down lists in action. Thank you for reading! Practice workbook for downloadCascading Dropdown Sample 1- easy version You may also be interested in
Excel: featured articles
Table of contents249 comments to "Making a dependent (cascading) drop down list in Excel" Older Comments
Older Comments Post a commentClick here to cancel reply. |