By default, Excel data validation only allows users to select one item from a predefined list of options. But fear not, as there is a solution. By using VBA, you can create drop-down lists with multiple selections. Continue reading
by Alexander Trifuntov, updated on
By default, Excel data validation only allows users to select one item from a predefined list of options. But fear not, as there is a solution. By using VBA, you can create drop-down lists with multiple selections. Continue reading
Comments page 12. Total comments: 705
thank you for this wonderful lessons. however, i was able to create a dropdown list but could not enable multiple selections. i copied and paste the VBA code but i keep getting error . saying compile error invalid outside procedure.
i dont know what to do.
Hi! You have inserted the code incorrectly. You can use the sample file linked at the end of this article.
Hi Alex,
When I input the code from the "How to enable multi-selection functionality in protected sheet" section, I get the error message: Ambiguous name detected: Worksheet_SelectionChange." Any ideas on how to fix this?
Hi! Look carefully at your code. The Worksheet_SelectionChange procedure is written twice.
Love this and your thorough steps! Can this be used on a call that uses "offset" data validation? I've copied and pasted the code and it doesn't seem to still work. Wondering if that could be the problem?
Hi! I don't really understand what you want to do. This code works with any Excel dropdown list. This dropdown list can be created in different ways. Read more: How to create drop down list in Excel: static, dynamic, editable, searchable
I have a drop down list created that offers up options based on how some previous cells are filled out. I input the VBA code in the worksheet where the drop down list is but it doesn't work. So I was wondering if it was because that cell and the drop down list has an offset formula in that cell.
Hi! The code works with any dropdown list that can be created in the ways described in this article: How to create drop down list in Excel. Check to make sure you have installed the code correctly.
Nice in theory; however, I feel like there must be some details missing in your explanation, as I can't even get past the first step. I even tried replicating your exact example on a new spreadsheet (created shorter Table/list) and typing literally what you had down to brackets/no spaces/double quotes/square brackets/etc. (=INDIRECT("Table1[Items]") And I got an error message "The source evaluates to an error, do you want to continue"? Generally, I am highlighting/selecting a column or series of rows for the 'Source' field. Were the "Table1[Items]" just a placeholder for highlighting/selecting that actual options? I tried that too but always get the same error message.
Hi! Here is the article that may be helpful to you: Create drop down list in Excel: static, dynamic, editable, searchable.
Hi Alexander,
This page is amazing! Thank you so much!
I'm trying to make it so that in certain columns, the options selected are separated by a comma, while in certain columns the options are separated by line breaks. However, when I try to run it, I receive an error message saying: Ambiguous name detected.
I figured out if you do an "If Destination.Column = 4 Then / DelimiterType = "/" ...lines copied from section of website you want... End If" You can define a new delimiter for each column. You have to do it individually though. I couldn't group multiple columns into one if loop.
Hi! You can set a different type of separator for a column. Here is an example of how you can set different separators for columns D and F.
If Destination.Column = 4 Then
DelimiterType = "; "
End If
If Destination.Column = 6 Then
DelimiterType = " - "
End If
Hi! You can only use one code and one type of delimiter on a worksheet.
Great article. I only have one comment for possible refinement of instructions.
Your example has the look up and the data on the same sheet. I often put look ups on a separate sheet.
You instructions on where to put the VS code should say "Select the sheet where you'll be selecting from your look up". As it's worded, it's initially unclear whether to paste the code into the sheet with the look up or the data entry.
Hi! The article notes that the code is worksheet specific, so be sure to add it to every worksheet where you want to allow multiple selections in dropdowns.
Can the VBA scripts somehow we specified in module within a workbook rather than within specific worksheets of the workbook?
Hi! Worksheet_SelectionChange to control the change in cell value, available only on the worksheet.
Alexandr, you are the best! Spasibo :)
Hi, Alexander. Your material is super! Just one question, a bit more complex :)
I've created an Excel table with multiselection dropdown in a specific column. Based on this table, I've created a pivot table with several slicers, one of these slicers refers to the column D with multiselection dropdown.
When in a certain cell in the column D several options are selected, but in another cell only one of these options is selected, in my slicer I see different options for filtering. For example: "X", "Y", but also "X,Y,Z". Is it possible to create a slicer that shows unique options only but allow filter them in all cells in column D regardless if in the same cell other options are selected together with the one I want to filter?
How this could be done?
Thanks in advance, Natalia
Hi! "X,Y,Z" is a text string. You cannot search for unique elements within a text string. To do this, you must split the elements of the text string into separate cells. I hope I answered your question. If you have any other questions, please don’t hesitate to ask.
This was super useful! One thing i noticed about using the VBA for multiple selections is that is removes the ability to start typing the item name when searching for a dropdown item. I am working with a very long dropdown list, so this functionality really comes in handy. Is there any way to have the ability added back into the sheet?
Hi! To create searchable drop-down lists in Excel, use data validation and named ranges. The steps are described below:
1. Enter data into Excel columns. For example, if you want to create a searchable drop-down list of products, enter the product name in one column and the corresponding code in another column.
2. Highlight the column with the data and click the “Formulas” button on the ribbon at the top of the screen. There, click “Define Names” button and name the named range. For more details on how to create a named range, read in this article: Excel names and named ranges: how to define and use in formulas.
3. Highlight the cells for which you want the drop-down list to appear and click the “Data” button on the ribbon at the top of the screen. From there, select the “Data Validation” option.
4. In the Data Validation dialog box, select “List” as the validation condition. In the Source field, enter the named range you created in step 2.
5. Select the “Dropdown in cells” and “Ignore whitespace” check boxes.
6. Click “OK” to close the dialog box.
Now, when you click on a cell with a dropdown, a list of all the elements in the named range will be displayed. To search for specific items, you can type multiple letters and Excel will filter the list accordingly. Select an item and the corresponding value will appear in the cell.
We hope this is helpful to you!
Is there something that can be added to the code to also allow there to be 0 selections with item removal?
Hi! To have no options to select from the drop-down list, simply remove drop-down list.
Should the ability to select multiple items from the drop list remain if the cell with the drop list is unlocked but the sheet itself is protected? (It doesn't in my case. The celll reverts to only the last item selected.)
Hi! Pay attention to the following paragraph of the article above: How to enable multi-selection functionality in protected sheet.
It covers your case completely.
My apology!! You have instructions for this--and they work like a charm!!!
Unbelievable! This works like a charm, and I know nothing about VBA. Thank you sooooo much!
Can you tell me how to retain formatting of dates when multiple items are selected? The options are, for example, Aug-23, Sep-23, etc., but when multiple options are selected, the format changes to 8/1/2023 and 9/1/2023. I've tried date formatting and custom formatting to no avail.
Hi! When you select a date from the drop-down list, Excel adds it in the Short Date Format that is set in your computer's Local Settings. Try using dates written as text in the drop-down list.
Oh my word. You're a genius. Thank you for your quick response!
Multiple selection worked in Excel 2016, but next to each row with multiple selection it throws an yellow error icon to its left saying:
"The value in this cell is invalid or missing. ".
It wants the value to match one of the listed items (eg. not multiple selection)
Hi! The macro works without errors in any version of Excel. Check how you followed the instructions in the article above.
The delimiter is comma+space. Nothing protected or locked.
Source: Jhon, Dave, Jim (any of these is fine but adding more than one, Excel complains with the yellow error symbol. The selection functionality works though. Tried all 3 vba options - same complaint
Hey Alex, this is amazing, thank you!!
I am a teacher, I have given my students 4 stations to attend each week - they get to choose where they go - but once they have chosen that specific station, I don't want them to be able to see that choice again - does this make sense? and if it does, how do I do that? I have all the kids names on the left, then the choices in 4 columns across the top.
example:
Tuesday Wednesday Thursday Friday
THIS IS NOW Drop down choice (4 of them) Drop down choice (4 of them) Drop down choice (4 of them) Drop down choice (4 of them)
THIS IS WANT Chooses 1 Only sees 3 remaining choices Only sees 2 remaining choices Only sees last choice available
and then I want to be able to clear their choices and start fresh the following week.
I hope this makes sense and I am not even sure if what I am asking for makes any sense, but I have it does.
If I am really pushing my luck, I would LOVE for the students to access this by scanning a QR code so I am the only one that sees what they picked for that day so their "friends" can't see what they picked, and in a perfect world, I would love to only allow a certain number to choose that station each day - but I think that is asking for something that doesn't exist, hahaha.
Anyway, I appreciate in advance, any help you can give me!!!
Thanks,
Tracy
Thanks Alexander.
Could you please suggest the code changes for using the multi-select drop-down to a specific Excel table Column? That is instead of identifying and using the column number of the Excel table column in the code, can the code be modified to use Table Name and the specific Column Name (Header).
Appreciate your support.
Thank you so much for this. I do not know about VBA but the instructions are really clear and they work as needed.
Works just as I needed it to. Thank you so much for this and for including the extra versions too. At first I thought I wouldn't need them, then thought ok, I don't want duplicates, and then right, what I actually want is no duplicates with the easy ability to modify the list item by item. So cool to see these all being separately supported in an easy to use way. Thanks again!
Hello! Your coding has been super helpful at multiple points for a project I've been slowly improving upon for work on and off for a few years now, so, thank you so much for that!
On that note, is there a way the display of the dropdown selections can be forced to arrange in a specific way regardless of the order in which they were selected? This would make filtering much simpler for my project. For example: can they be ordered in alphabetical order or by the order in which they are displayed on the dropdown list?
Thanks and have a great day!
Nicole
Dear Alexander,
I am so impressed with this page, it's easy to understand, and mostly pre-empt the task and provide the solution. I was looking for this option for quite sometime, however mostly I got though google search, was partially solving my issues. However your solution over delivered. I wish you all the best .
Thanks,
Sukanta
Many thanks this helped me a lot
Hi again Alex, I am so dopey, I re-read your comments
"To get each selection in a separate line in the same cell, set DelimiterType to Vbcrlf. In VBA, it is a constant for the carriage return and line feed characters.
More precisely, you change this code line:
DelimiterType = ","
to this one:
DelimiterType = vbCrLf"
and deleted the " " and it fixed it.
Hi Alex, I have booked marked your page and find your knowledge on excel the most useful and insighting. I have nominate 3 columns and am changing the DelimiterType form"', " to = "vbCrLf" however when i save it, close it then reopen it shows this in the column; Abusive Behaviour Towards StaffvbCrLfAlcohol on Premises.
Please advise what i am doing wrong.
Hi! See the corresponding paragraph in the article above. You can also see the sample code in the example file linked at the end of the article.
Hi Alexander,
This page is incredible! Thank you so much!
I'm having some trouble though isolating the multiple dropdown selection to one column. In your instructions, you said about adding the code "If Not Destination.Column = 4 Then GoTo exitError". The only thing I changed was 4 to 5 as that's the column I need the dropdowns in.
However, it is still affecting my whole worksheet, so if I go to a dropdown in column 6 (F) where I only want a single selection, it allows me to put in multiple selections.
Please can you advise where I've gone wrong and offer a solution?
Hi! Pay attention to which sheet code you added this string of code to. The code works only on the sheet in which it is inserted.
Sorry, I should have looked at the previous comments! For those that are having similar problems, I resolved the issue by inserting the following below the "If Destination.Count > 1 Then Exit Sub" line:
If Not Destination.Column = 5 Then Exit Sub
The worksheet now allows me to make my multiple selections in column 5 (E), and single selections in column 6 (F).
Hi Alexander
thanks for your comprehensive useful post. I have a problem here, I did everything same as you've mentioned here, and it works as multiple selection with removal enabled, so I save my worksheet as macro enabled, but after I close and reopen the file, it won't work as multiple selection but only single selection
Hi! Your file has macros disabled. Save the file as xlsm. Try using these recommendations: How to enable and disable macros in Excel.
Hi Alexander, Thanks for the post very useful. Can we restrict selection of entries to 3 max based on comma's. May be stop at selected 3 entries and error when adding the 4th one. Appreciate if you could help with the code to use in the above example.
Hi! As much as I'd like to help, I'm overloaded with some current projects at the moment and won't be able to take time for your task. Custom code changes are quite time-consuming.
no problem. Thank you!
Thanks, sir. It's my first time trying macro. It is very useful for my project. All Thanks to your clear tutorial and code.
Hey, is it possible to select a few items at one go from the dropdown list? For example, instead of selecting "Apples" , "Oranges", separately, is there a way to select multiple items at one go? So that Apples and Oranges will be displayed together at the same time without an extra step of selecting each item one by one. Perhaps like a checkbox before each item in the dropdown list.
Hi! Unfortunately, the dropdown list in Excel only allows you to select one value at a time.
Hello. I used the VBA code in an Excel spreadsheet to allow multiple drop-down box selections in separate lines. Instead of DelimiterType = “,” I changed it to Delimiter = vbCrLf. I saved it as a xlsm file and it worked great. I got out of the spreadsheet and saved it. When I reopened to test it again, it would not work even though the same code was there. I have deleted the code and recopied it and also saved as a different xlsm file name. Do you have any ideas on what might have happened? I’m clueless and out of things to try. Any assistance would be appreciated.
Hi! You can use the ready-made code from the example file (Selections in separate lines sheet) linked to at the end of this article.
Is it possible to create a drop down list in a blank spreadsheet without creating a table?
Hi! You can find useful information in this article: How to create drop down list in Excel: dynamic, editable, searchable.
Hi,
thanks for this, very useful.
I am getting a bug on the removal function.
With using a simple example where I have on my list Green Apples, Oranges, Apples; after selecting "Apples" again, the macro removes the first "Apples" - so it returns: Green , Oranges, Apples - which is not what I am expecting.
is there a way to fix this?
Thanks in advance,
Hello! Thank you for your comment. We have changed the macro code. Now the values are deleted correctly.
Hello First thank you - I was trying to read the comments on how to make this work for all sheets in a workbook rather then copying duplicate code onto each sheet (if I read the instructions correct)
Hello!
To run a macro on all worksheets in a workbook at once, the Workbook_SheetChange procedure is declared in the Workbook object and written in the ThisWorkbook code window. You can find the ThisWorkbook object in the VBAProject window below the worksheet list. Click on it and in the opened window add the code of the macro you need. You will need to add an additional parameter ByVal Sh As Object to the procedure.
For example, instead of
Sub Workbook_SheetChange(ByVal Destination As Range)
write
Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Destination As Range)
I would like to use the "Multi-selection dropdown with item removal" but also allow for a write in on one option.
For example: Location: Location A, Location B, Location C, Other Location:
and the responder could click: "Location A" and "Other Location:", then go into the write in bar and type in "Garden" after "Other Location:"
When I turn off the error alert in Data Validation I am able to do this but then the options start to duplicate themselves in the field: "Location A, Other Location:, Location A, Other Location: Garden"
Thank you for your assistance
Hi! The macro assumes that all values in the cell will be entered from the drop-down list. When you are correcting a cell manually, all of its content is considered as a new value and added to the existing text in the cell. The result is duplication.
If you have "Location A, Other Location:" written in a cell and you want to add "Garden". When editing the cell, delete all text, type "Garden", and press Enter. You will get "Location A, Other Location:,Garden".
How do I adjust this code to work, in a single column instead of in multiple data validation lists?
Hi! I kindly ask you to take a closer look at the following paragraph of the article above: Multi-select dropdown for specific columns, rows, cells
This code would prove to be very useful for me, but for some reason doesn't work for me? I downloaded the example workbook, but unfortunately all the drop downs just revert to normal - only allow single selection as per the list validation.
I am guessing there is a setting in my excel that needs correcting or perhaps the version i am using isn't compatible?
Any advice would be appreciated.
Hi! If I understand your task correctly, the following tutorial should help: How to enable and disable macros in Excel.
Great solution Alexander. Very useful. Well done !
Hi,
Would be of a help if there is a VBA macro to auto map data validation list map basis the column header. Say for example for columns D to L with header name, I have the list of values defined with the same header name from column P to X. Data validation is to be set for column D basis column P, column E basis column Q and so on basis the matching column names. The header range where the data validation and the header range where the list values provided should be user selection as this may vary basis the requirement.
Hi! If I understand correctly, a special macro is required for your purposes. We offer a universal solution, where you can specify all the columns in which the macro should run.
Is there a way to have the "multiple selection drop down list with item removal" appear in the same workbook but different worksheet than the key from which you want to pull content? Also, how does the VBA code know where to pull the key content from. For example, I started on the "key worksheet" but cannot find how to tell the code to pull list items only from let's say "Column B" and then create a multi list in Column D in another worksheet (titled "Master").
I know if I add code: If Not Destination.Column = 4 Then GoTo exitError
it should put content in column 4 but presumably it will be the worksheet I am creating the code for (my "key" worksheet) instead of the "master" worksheet where I want to have the drop downs.
Next, and the biggest question, how do I run or enact the macro so it starts working? I have entered the code but see no changes in my drop down lists. They are single drop downs which I created prior to adding in this code.
Hi! Read the article carefully. It has all the explanations you need. You can create a drop-down list in any of the ways described, for example, in these articles: Create drop down list in Excel: static, dynamic, editable, searchable or How to make a dependent (cascading) drop-down list in Excel.
The VBA code in this article does not create any drop-down list. It does allow a drop-down list to add multiple values to a cell. To do so, it must be placed on the same sheet as the drop-down list. There are additional settings to make the macro work only on individual rows, columns, or cells. You can read about that in the article above.
The code you wrote allows the macro to work only in column D. It doesn't put anything anywhere else.
I hope I answered your question.
Great post.
I found 1 issue, when the worksheet is protected.
I applied your instructions for the following
To restore protection, at the end of the code, before this line:
exitError:
Add this code:
ActiveSheet.Protect Password:="password"
This will unlock the worksheet on any list box that is single select.
A list box defined as multi-select works as expected with this added following the protection additions
If Destination.Address "$D$15" And Destination.Address "$C$86" And Destination.Address "$C$87" Then GoTo exitError
I moved the ActiveSheet.Protect Password:="password" to right after Application.EnableEvents = True and now it no longer unlocks the worksheet for single list cells.
Place the code where specified in the article, and remember the security risk.
Hi Alexander - I needed to use the fix provided by Chris Strabley as well. Suggest reviewing your provided code to remedy the sheet unlock when single validation cells selected.
Great code by the way, helped me out significantly.
Hi! We won't change the macro code for these suggestions, as most users don't need to. Also pay attention to the following paragraph: Enable multi-selection functionality in protected sheet. You can change the code for yourself, remembering about the security risk.
Thank you for this. I am running into an issue that every time I add the code for a specific column If Not Destination.Column = 4 Then GoTo exitError on either the Multi item selection dropdown or or the multiselection dropdown with removal. The multiselection doesn't work any more... I am adding it after:
Option Explicit
Private Sub Worksheet_Change(ByVal Destination As Range)
Dim DelimiterType As String
Dim rngDropdown As Range
Dim oldValue As String
Dim newValue As String
DelimiterType = ", "
If Destination.Count > 1 Then Exit Sub
On Error Resume Next
Set rngDropdown = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitError
If rngDropdown Is Nothing Then GoTo exitError
Thoughts?
Thanks,
Hello! With this code, multiple selection only works in column D. What exactly does not work for you? Describe it in more detail.
NVM. I figured it out.
Thank you for making me look smart in my meetings!'
Sorting a worksheet column after adding this code does not work properly. Is there a way around this issue? List items do not appear in the column sort drop down list, When they do appear the list the requested sort list item does not return only the requested item. Thoughts?
I don't quite understand your problem. The multiple selection code only affects the operation of the drop-down list and nothing else. It creates a text string of multiple dropdown list items in a cell. I could not find a problem with the sorting. Describe your problem in more detail.
Hi,
Hope my message finds you well.
I maked an excel file with VBA which works perfectly but stop working on others computer when i share it by eamil.
How can i solve this issue please
Hello! I assume that when you send the file by email, the macros are automatically blocked. Try using these recommendations: How to enable and disable macros in Excel. I hope this will help.
Hi Alexander Trifuntov (Ablebits Team)
I want to know if there is a solution to use INDIRECT function on a multiple selected dropdonw list.
Hi! You can create a drop-down list any way you want. For example, using these guidelines: Create drop down list in Excel: static, dynamic, editable, searchable. The macro will work with this list.
You can change the VBA code and specify the column number in which the multiple selections will be made.
After code:
If rngDropdown Is Nothing Then GoTo exitError
add code:
If Not Destination.Column = 4 Then GoTo exitError
Thanks
But what if my column if more than one like column 15 and 16 and 19
Just below that example in the article there is an answer to your question.
If Destination.Column <> 15 And Destination.Column <> 16 And Destination.Column <> 19 Then GoTo exitError
Infinitely Thanks.
I realized you already solve it in "Multi-select dropdown for specific columns, rows, cells" section
Excellent code, thank you!
I need to have both multi-select drop down related VBA procedures you kindly allowed in your website work for one sheet because I have some columns here i want multi-select picks to allow duplicates and some columns to allow multi-select picks to NOT allow duplicates. Do i paste both procedures codes into the same code window? Do i need a call statement above the 2 procedures to call the one or the other depending on what column i am working in
thank you!
Craig
Hi! Unfortunately, only one of the three codes available in the article can be placed on a single sheet.
thanks very much for your prompt reply!
Is you have any advice on where I can go to get some columns to allow multi select and dupes and some to not allow multi select dupes to work on same sheet, I would love to hear it!
Craig
Hi! Pay attention to the following paragraph of the article above: Multi-select dropdown for specific columns, rows, cells. I hope it’ll be helpful.
It was very useful, thanks a lot.
Hello,
When I pasted the code to different sheets, there is bug at '' If Destination.Count > 1 Then Exit Sub''.
Could you please kindly explain to me what might be the reason behind?
Best and thanks!
Hi! This operator allows you to select only one value in the drop-down list. You are trying to add multiple values at once.
Hi, is it possible to achieve similar "multi select drop down list" functionality in Office Script in Excel for WEB?
or perhaps as an add-in for Excel for web?
I already answered this question in the comments. Unfortunately, Visual Basic only works in the desktop version of Microsoft Office.
I am trying to use this but the code is not running. I have the selections stored in a separate sheet in the same workbook, which, for other users, you have said should not change anything. I pasted the code in the worksheet-specific module and saved it, but the code does not work in the sheet. What might be the problem with this?
When I download the example sheet, the code that is already in that sheet does not work also.
Hi! Try to use this recommendations: How to enable and disable macros in Excel. I hope it’ll be helpful.