The article shows how to create an Excel drop down that allows users to select multiple items with or without duplicates.
Excel has come a long way since its inception and introduces more and more useful features with each new release. In Excel 365, they've added the ability to search within data validation lists, which is a huge time-saver when working with large sets of data. However, even with this new option, out-of-the-box Excel still only allows selecting 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. With the ability to prevent duplicates and remove incorrect items, this feature can streamline data input and improve accuracy in your Excel spreadsheets.
How to make Excel drop down with multiple selections
Creating a multi-select drop down list in Excel is a two-part process:
- First, you make a regular data validation list in one or more cells.
- And then, insert the VBA code at the back end of the target worksheet.
It also works in the reverse order :)
Create a normal drop-down list
To insert a drop down list in Excel, you use the Data Validation feature. The steps slightly vary depending on whether the source items are in a regular range, named range, or an Excel table.
From my experience, the best option is to create a data validation list from a table. As Excel tables are dynamic by nature, a related dropdown will expand or contract automatically as you add or remove items to/from the table.
For this example, we are going to use the table with the plain name Table1, which resides in A2:A25 in the screenshot below. To make a picklist from this table, the steps are:
- Select one or more cells for your dropdown (D3:D7 in our case).
- On the Data tab, in the Data Tools group, click Data Validation.
- In the Allow drop-down box, select List.
- In the Source box, enter the formula that indirectly refers to Table1's column named Items.
=INDIRECT("Table1[Items]")
- When done, click OK.
The result will be an expandable and automatically updatable drop-down list that only allows selecting one item.
Tip. If the method described above is not suitable for you for some reason, you can create a dropdown from a regular range or named range. The detailed instructions are here: How to create Excel data validation list.
Insert VBA code to allow multiple selections
This is the core part of the process that does the magic. To turn a regular single-selection picklist into a multi-select dropdown, you need to insert one of these codes in the back end of your target worksheet:
- VBA code for multi-select drop down with duplicates
- VBA code for multi-select drop down without duplicates
- VBA code for multi-selection dropdown with item removal
To add VBA code to your worksheet, follow these steps:
- Open the Visual Basic Editor by pressing Alt + F11 or clicking the Developer tab > Visual Basic. If you don't have this tab on your Excel ribbon, see how to add Developer tab.
- In the Project Explorer pane at the left, double-click on the name of the worksheet that contains your drop-down list. This will open the Code window for that sheet.
Or you can right-click the sheet's tab and choose View Code from the context menu. This will open the Code window for a given sheet straight away.
- In the Code window, paste the VBA code.
- Close the VB Editor and save your file as a Macro-Enabled Workbook (.xlsm).
That's it! When you go back to the worksheet, your drop-down list will allow you to select multiple items:
VBA code to select multiple items in dropdown list
Below is the code to make a data validation list that allows selecting multiple items, including repeated selections:
How this code works:
- The code enables multiple selections in all drop down lists on a particular sheet. You do not need to specify the target cell or range reference in the code.
- The code is worksheet specific, so be sure to add it to each sheet where you want to allow multiple selections in drop down lists.
- This code allows repetition, i.e. selecting the same item several times.
- The selected items are separated with a comma and a space. To change the delimiter, replace ", " with the character you want in DelimiterType = ", " (line 7 in the code above).
Note. The same character cannot be used as both the delimiter and part of the dropdown items. In our code, the default delimiter is a comma followed by a space (", "), so this combination of characters should not appear anywhere within the dropdown items themselves to avoid conflicts. If you change the delimiter to a single space (" "), bear in mind that the code will only function correctly for single-word items, failing to handle multi-word items containing spaces.
Excel multi-select dropdown without duplicates
When selecting from a large list, users can sometimes pick the same item more than once without noticing. The code below solves the problem of duplicates in a multi-selection data validation drop down list. It lets users pick a particular item only once. If you try to select the same item again, nothing will happen. Pretty cool, right?
Multi-selection dropdown with item removal
When users need to select multiple options but can make mistakes or change their minds during the selection process, a multi selection dropdown that allows for the removal of incorrect items can be a lifesaver.
Consider a scenario where you need to assign multiple tasks to team members using a drop-down list. With Excel's default functionality, the only way to remove an incorrectly assigned task is by clearing the entire contents of the cell and starting over. With the ability to remove individual items from the selection, the team can effortlessly modify task assignments without confusion or errors.
The code below implements the item removal functionality in a simple and intuitive way: the first click on an item adds it to the selection, and a second click on the same item removes it from the selection.
The below demo highlights how the multi selection dropdown with removal functionality works in Excel. The users can select multiple options from the data validation list and make adjustments on the fly. A streamlined and effective approach to managing selections!
How to make a multiple selection dropdown with custom delimiter
The character that separates items in the selection is set in the DelimiterType parameter. In all the codes, the default value of this parameter is ", " (a comma and a space) and it is located in line 7. To use a different separator, you can replace ", " with the desired character. For instance:
- To separate the selected items with a space, use DelimiterType = " ".
- To separate with a semicolon, use DelimiterType = "; " or DelimiterType = ";" (with or without a space, respectively).
- To separate with a vertical bar, use DelimiterType = " | ".
For example, if you change the delimiter to a vertical slash, your multi-select picklist will look as follows:
How to create dropdown with multiple selections in separate lines
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
As a result, each item that you select from the dropdown list will appear in a new line:
How to create multi-select dropdown for specific columns, rows, cells and ranges
All the codes described in this tutorial work across an entire sheet. However, you can easily modify any of the codes, so it only applies to specific cells, rows, or columns as needed. For this, find this line of code:
If rngDropdown Is Nothing Then GoTo exitError
Add immediately after it, add a new line specifying where to allow multiple selections, as explained in the below examples.
Multi-select drop-down for specific columns
To allow selecting multiple items in a certain column, add this code:
If Not Destination.Column = 4 Then GoTo exitError
Where "4" is the number of the target column. In this case, the multi-select dropdown will be only enabled in column D. In all other columns, dropdown lists will be limited to a single selection.
To target several columns, specify their numbers using this code:
If Destination.Column <> 4 And Destination.Column <> 6 Then GoTo exitError
In this case, the multi-select dropdown will be available in columns D (4) and F (6).
Multi-selection dropdown for certain rows
To insert multiple drop-downs in a specific row, use this code:
If Not Destination.Row = 3 Then GoTo exitError
In this example, replace "3" with the row number where you want to enable multi-select dropdowns.
To target multiple rows, the code is as follows:
If Destination.Row <> 3 And Destination.Row <> 5 Then GoTo exitError
Where "3" and "5" are the rows where selecting multiple items is allowed.
Multiple selections in specific cells
To enable multiple selections in particular cells, add one of the below code lines.
For a single cell:
If Not Destination.Address = "$D$3" Then GoTo exitError
For multiple cells:
If Destination.Address <> "$D$3" And Destination.Address <> "$F$6" Then GoTo exitError
Just remember to replace "$D$3" and "$F$6" with the addresses of your target cells.
Multi-select drop-down for specific range
To limit your multi-select dropdown to a particular range, replace this line of code:
If Intersect(Destination, rngDropdown) Is Nothing Then
with this one:
If Intersect(ActiveCell, Range("C3:D10")) Is Nothing Or Intersect(Destination, rngDropdown) Is Nothing Then
The range of interest is specified directly in the code (C3:D10 in the above example). This modification offers a more efficient approach to handing ranges - instead of individually listing 16 cells, you use a single range reference.
How to enable multi-selection functionality in protected sheet
To enable a multi-select dropdown functionality in a protected worksheet, simply insert the following code into the sheet where you've added the primary code. This "protected sheet" code should be added after the main code.
Before adding this code to your worksheet, remember to replace "password" with the actual password you used to protect the sheet. And this is the only change that needs to be made. The code will automatically detect the presence of a dropdown list in a given cell and allow editing of that cell. In all other cells, editing will remain restricted.
Note. Please be aware that including your real password in the code could lead to a security risk. To ensure the safety of your workbook, store it in a secure location that is protected against unauthorized access or use.
So, there you have it - an Excel dropdown list with multiple selections. Adding this awesome feature to your spreadsheets will increase the accuracy of your data input and help you get your work done faster!
Practice workbook for download
Multi-selection dropdown - examples (.xlsm file)
622 comments
How can I make a dropdown of a specific cell range associated with a cell containing a specific text where the text can vary based on a dropdown? For example, there is a data sheet that contains a column titled Product that has 3 products; another column titled Module that has 19 options each of which is associated with a specific product; a third column with 85 Agents who in turn are associated with specific modules. I'm trying to make a dropdown that if I select "x" module, it will only list the agents associated with that module. By the same token, a dropdown that would only list the modules associated with a specific product.
Hi! We have a special tutorial that can help to solve your problem: How to make a dependent (cascading) drop-down list in Excel.
Alex, this is amazing! Thank you! Quick question: is there a way to make a multi-selection available to only one column in a worksheet and have other data validation be single selection? Thanks.
Hi! Pay attention to the following paragraph of the article above: Multi-select dropdown for specific columns, rows, cells
How can I adapt the 'Multi-selection dropdown with item removal' code you provided to make it work for 2 columns in the worksheet (column 11 & column 12) ONLY. They both have separate drop-down lists, I want people to be able to multi-select more than 1 thing from the drop down list but give them chance to remove things selected by mistake without having to delete and start again. When I added If Destination.Column 4 And Destination.Column 6 Then GoTo exitError after section specified it didn't work and errored at bit of code with LEFT and RIGHT in ikt
Hi! If you need the code to work in columns 11 and 12, specify those column numbers in the code, not 4 and 6. All the necessary information is in the article above.
Really useful information here. I would like to know if there is a way to put this code in an addin and enable all workbooks to have access to the code instead of copying the code to the worksheet. I know the code is workbook worksheet specific but how can you remove this limitation?
Hi! Unfortunately, Worksheet_Change only works on a worksheet.
This code works great, thank you for the time spent creating this! My one question, i used the Multi-Select version of your code and its tailored to one column, column 3 but i would like to sort the results alphabetically in each cell that has multiple items selected, Im guessing i need a sort command between the last two "End If" is this correct? Can you provide an example?
Thanks again for the well crafted code.
Hi! A drop-down list creates a text string in a cell. To sort individual words in the text, you must write special VBA code. Or you can split the text into cells, then sort and merge the text strings again.
Or you can use the TEXTSPLIT function to split the text, and then combine the text strings using the TEXTJOIN function. For example:
=TEXTJOIN(", ",TRUE,SORT(TEXTSPLIT(A1,,", ")))
I am enabling this function for 2 cells in a protected worksheet. However, this function for multiple selection with removal is working only when it's unprotected. My code is pasted below, thank you so much!
'https://www.ablebits.com/office-addins-blog/create-multi-select-dropdown-excel/
Option Explicit
'Multi-selection dropdown with item removal
'https://www.ablebits.com/office-addins-blog/create-multi-select-dropdown-excel/
Private Sub Worksheet_Change(ByVal Destination As Range)
Dim rngDropdown As Range
Dim oldValue As String
Dim newValue As String
Dim DelimiterType As String
DelimiterType = vbCrLf
Dim DelimiterCount As Integer
Dim TargetType As Integer
Dim i As Integer
Dim arr() As String
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
'define only the cells need to enable multiple selection
If Destination.Address Range("Destination_Expiring_Coverage").Address And Destination.Address Range("Destination_Renewing_Coverage").Address Then GoTo exitError
TargetType = 0
TargetType = Destination.Validation.Type
If TargetType = 3 Then ' is validation type is "list"
Application.ScreenUpdating = False
Application.EnableEvents = False
newValue = Destination.Value
Application.Undo
oldValue = Destination.Value
Destination.Value = newValue
If oldValue "" Then
If newValue "" Then
If oldValue = newValue Or oldValue = newValue & Replace(DelimiterType, " ", "") Or oldValue = newValue & DelimiterType Then ' leave the value if there is only one in the list
oldValue = Replace(oldValue, DelimiterType, "")
oldValue = Replace(oldValue, Replace(DelimiterType, " ", ""), "")
Destination.Value = oldValue
ElseIf InStr(1, oldValue, DelimiterType & newValue) Or InStr(1, oldValue, " " & newValue & DelimiterType) Then
arr = Split(oldValue, DelimiterType)
If Not IsError(Application.Match(newValue, arr, 0)) = 0 Then
Destination.Value = oldValue & DelimiterType & newValue
Else:
Destination.Value = ""
For i = 0 To UBound(arr)
If arr(i) newValue Then
Destination.Value = Destination.Value & arr(i) & DelimiterType
End If
Next i
Destination.Value = Left(Destination.Value, Len(Destination.Value) - Len(DelimiterType))
End If
ElseIf InStr(1, oldValue, newValue & Replace(DelimiterType, " ", "")) Then
oldValue = Replace(oldValue, newValue, "")
Destination.Value = oldValue
Else
Destination.Value = oldValue & DelimiterType & newValue
End If
Destination.Value = Replace(Destination.Value, Replace(DelimiterType, " ", "") & Replace(DelimiterType, " ", ""), Replace(DelimiterType, " ", "")) ' remove extra commas and spaces
Destination.Value = Replace(Destination.Value, DelimiterType & Replace(DelimiterType, " ", ""), Replace(DelimiterType, " ", ""))
If Destination.Value "" Then
If Right(Destination.Value, 2) = DelimiterType Then ' remove delimiter at the end
Destination.Value = Left(Destination.Value, Len(Destination.Value) - 2)
End If
End If
If InStr(1, Destination.Value, DelimiterType) = 1 Then ' remove delimiter as first characters
Destination.Value = Replace(Destination.Value, DelimiterType, "", 1, 1)
End If
If InStr(1, Destination.Value, Replace(DelimiterType, " ", "")) = 1 Then
Destination.Value = Replace(Destination.Value, Replace(DelimiterType, " ", ""), "", 1, 1)
End If
DelimiterCount = 0
For i = 1 To Len(Destination.Value)
If InStr(i, Destination.Value, Replace(DelimiterType, " ", "")) Then
DelimiterCount = DelimiterCount + 1
End If
Next i
If DelimiterCount = 1 Then ' remove delimiter if last character
Destination.Value = Replace(Destination.Value, DelimiterType, "")
Destination.Value = Replace(Destination.Value, Replace(DelimiterType, " ", ""), "")
End If
End If
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
exitError:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.UnProtect Password:=strPwd
On Error GoTo exitError2
If Target.Validation.Type = 3 Then
Else
ActiveSheet.Protect Password:=strPwd
End If
Done:
Exit Sub
exitError2:
ActiveSheet.Protect Password:=strPwd
End Sub
If you don't have enough knowledge in VBA, just follow the instructions in the article above. There is no value assigned to the strPwd variable.
I have two sheets in my workbook. One is for tracking inventory and the other contains all the various select lists for different columns of data in the inventory sheet. For example, categories, subjects, status, etc. I can match-up the single select columns and lists across the two sheets but, I'd like the "subject" column to allow multiple entries as explained here. How to I tell it which sheet & column in the List sheet contains the data I want to use in a specific column in the Inventory sheet?
Clarification, How do I tell it which column in the List sheet contains the data I want to select from and add to a specific column in the Inventory sheet.
Hi! As described in the article above, you can specify a sheet, column, or individual cells in which the drop-down list can make multiple selections.
How do I combine the code for "VBA code to select multiple items in dropdown list" and "How to enable multi-selection functionality in protected sheet"
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
If Intersect(Destination, rngDropdown) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newValue = Destination.Value
Application.Undo
oldValue = Destination.Value
Destination.Value = newValue
If oldValue = "" Then
'do nothing
Else
If newValue = "" Then
'do nothing
Else
Destination.Value = oldValue & DelimiterType & newValue
' add new value with delimiter
End If
End If
End If
exitError:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Unprotect password:="password"
On Error GoTo exitError2
If Target.Validation.Type = 3 Then
Else
ActiveSheet.Protect password:="password"
End If
Done:
Exit Sub
exitError2:
ActiveSheet.Protect password:="password"
End Sub
Hi! You have declared Worksheet_SelectionChange procedure twice. This is incorrect in VBA. Delete the code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
I used the code below after your suggestion to remove the piece you mentioned. It's still not working, it won't let me select the multiple values - I see it protecting the sheet after entering the code, but won't allow for multiple value selection. I'm wondering if my add in of the protection code is in the wrong place? would you be able to combine the 2 codes into one as it's supposed to run and I can copy and paste that into excel? I would be so greatful for the assistance.
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
If Intersect(Destination, rngDropdown) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newValue = Destination.Value
Application.Undo
oldValue = Destination.Value
Destination.Value = newValue
If oldValue = "" Then
'do nothing
Else
If newValue = "" Then
'do nothing
Else
Destination.Value = oldValue & DelimiterType & newValue
' add new value with delimiter
End If
End If
End If
exitError:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Unprotect password:="password"
On Error GoTo exitError2
If Target.Validation.Type = 3 Then
Else
ActiveSheet.Protect password:="password"
End If
Done:
Exit Sub
exitError2:
ActiveSheet.Protect password:="password"
End Sub
Hi! I have your code working without problems on a protected worksheet. Check on which worksheet this code is installed. Also try the recommendations on how to enable macros from the previous comment.
Thank you for the tutorial. I have copied the code exactly, and the first time I used it it worked Perfectly, However, after saving it as a Macro enable excel sheet (as instructed) it no longer allows the multiple selection. I re-copied the code and it is still not working. Do you have any suggestions on how to correct this?
Hi! I am unable to verify your file. However, I hope this information will help to solve the problem: How to enable and disable macros in Excel.
I tried the code, but it does not work with me. I then downloaded your file, in fact multi selection does not work in your file as well. There is no error displayed, but it keeps showing one selection only. Do I have any issue on excel setting or else?
Can anyone help?
Hi! Your Excel has macros disabled. Here is the article that may be helpful to you: How to enable and disable macros in Excel.
Hi Alexander,
Wow, this is spectacular well written information. Thank you very much. I have a question about Multiple selections in specific cells. In you example you list just two cells, however what would be the process for several (5) cells.
Hi! Add as many And Destination.Address <> "[address]" conditions to the code as necessary.
I have another question, I have a drop-down menu In which I have 3 variables like resistanxe, Voltage, current, in second column B1
If one of the variables is selected I would like to have two variables pop upoutside this list under the $B$1 in $B$2, $B$3,
Those $B$2, $B$3have their own variables like for $B$2 coffin Manson, Arhenius, but they should disappear if $B$1 ( current is selected). Or a other variable in $B$1. So if I have $B$1 on resistance= I will get two strings variables in $B$2, $B$3, if values are written in $C$2; $C$3; they should write it to the second sheet for a calculation. And stay there. They will be permanently saved somehow. I didn’t find a good solution for this. Please help or refer to a good explanation
Hi! Your explanation is not quite clear. However, you can get the values in B2 and B3 depending on the value in B1 either by using the IF formula or by using VBA. These pieces of info are not enough to give you a formula.
This is incredibly helpful! Wow thank you for sharing.
I am trying to reference the various values selected in the drop down. Before, when it was just one value it was fairly straightforward. Now with multiple values I'm having trouble splitting them apart to be referenced. Any tips?
Hi! The macro creates a text string of multiple values in a cell. You cannot reference part of the text string, only the entire cell.
This tutorial was immensely helpful however, I am having an issue with 365 with the protected sheet code. Prior to protecting the sheet, the VBA code allows multi select in column 16 & 23 (without the additional protect code). Once the sheet is protected with these columns unlocked, I can only single select. I unprotected the sheet, added the additional VBA for protecting the sheet (edited the password), protected the sheet again, and have the same result- the sheet no longer allows multiselect once the protection is initiated.
I read a previous message from a user who had the same issue but did not see a resolution. This is the code in my sheet- is there something I should be adding or an additional step I am missing? Thank you.
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
If Destination.Column 16 And Destination.Column 23 Then GoTo exitError
If Intersect(Destination, rngDropdown) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newValue = Destination.Value
Application.Undo
oldValue = Destination.Value
Destination.Value = newValue
If oldValue = "" Then
'do nothing
Else
If newValue = "" Then
'do nothing
Else
Destination.Value = oldValue & DelimiterType & newValue
' add new value with delimiter
End If
End If
End If
exitError:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Unprotect password:="password"
On Error GoTo exitError2
If Target.Validation.Type = 3 Then
Else
ActiveSheet.Protect password:="password"
End If
Done:
Exit Sub
exitError2:
ActiveSheet.Protect password:="password"
End Sub
I see the sheet unprotecting and protecting itself any time I use the dropdown, but multiselect is no longer possible.
Hi! In your code, instead of
If Destination.Column 16 And Destination.Column 23 Then GoTo exitError
must be written down
If Destination.Column <>16 And Destination.Column <>23 Then GoTo exitError
In this case, everything works for me.
Before installing the code, you can try to remove the protection from the worksheet. It will be automatically enabled with this code.
Hello, everything works great for me until I attempt to add the code for a protected sheet. I am inputting my password, but I am getting an error for an ambiguous name. I believe it is related to how the code is formatted. Any help would be appreciated!
To expand, when I remove the previous instance of the "worksheet_Selectionchange" I no longer get the error, but I cannot make multiple selections within my worksheet.
Hi! Your description of the problem is not very clear. I can assume that you are adding two Worksheet_SelectionChange codes to the sheet. There should be only one code with this name. To work on a protected sheet, make changes in the code as described in the article above.
Once my protected sheet code is added below the original code. I do not get any errors on a protected sheet, but the sheet works as if there has been no VBA code at all. In other words, when I attempt to add multiple selections, it only displays the most recent selection that has been chosen. I hope this helps to clear up the previous comment.
I am currently having the same issue. Once the sheet is protected, the multiselect is not available.
Hi! Unfortunately, I can't see your workbook. Worksheet_Change and Worksheet_SelectionChange code must be added to the protected worksheet. All this is described in detail in the article above.
Attached below is how I have the code structured. I hope this helps! I appreciate the quick responses!
Option Explicit
Private Sub Worksheet_Change(ByVal Destination As Range)
Dim rngDropdown As Range
Dim oldValue As String
Dim newValue As String
Dim DelimiterType 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
If Intersect(Destination, rngDropdown) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newValue = Destination.Value
Application.Undo
oldValue = Destination.Value
Destination.Value = newValue
If oldValue "" Then
If newValue "" Then
If oldValue = newValue Or _
InStr(1, oldValue, DelimiterType & newValue) Or _
InStr(1, oldValue, newValue & Replace(DelimiterType, " ", "")) Then
Destination.Value = oldValue
Else
Destination.Value = oldValue & DelimiterType & newValue
End If
End If
End If
End If
exitError:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Unprotect Password:="password"
On Error GoTo exitError2
If Target.Validation.Type = 3 Then
Else
ActiveSheet.Protect Password:="password"
End If
Done:
Exit Sub
exitError2:
ActiveSheet.Protect Password:="password"
End Sub
This code does not match the code suggested in the article and in the sample file linked at the end of the article.
I do not believe that the sample file includes the code for protected sheets. When adding the protected sheet code, I must delete the other mention of "worksheet_selectionchange" or I receive an ambiguous name error. The code above contains both the original code and protected sheet code, but it is obvious that it is inserted incorrectly as you have mentioned in the above comment. How should the protected sheet code be added to the original code?
You have correctly written how the code should be inserted. But you changed the macro code. Pay attention to
Destination.Value = newValue
If oldValue "" Then
If newValue "" Then
If oldValue = newValue Or _
Copy the code carefully.
I believe that error in the code is from copying and pasting the VBA code to this comment section. I confirmed that my code in excel is identical to the code in the above post. When the sheet is unprotected, the code works perfectly, but when the sheet is protected it only allows one item from the drop down to be added to each cell.
This tutorial was immensely helpful; I created a drop-box list and am able to select multiple choices. When I copied the Excel Worksheet to the next Sheet, this function doesn't copy over, even when I attempt to highlight the cells and reinsert the code. Is there an effective way to copy this functionality?
Hi! As noted in the article above, the code is specific to the worksheet, therefore be sure to add it to each worksheet where you want to allow multiple selections in the drop-down lists. Also, a worksheet can only have one VBA code from the three offered to you.
Yes, I saw that information and I have ensured to use only one type of VBA code, and confirmed that it is listed under each sheet tab in the Excel Worksheet, and it still only works for the first entry. Any type of troubleshooting may I perform to confirm if there is an error in the process of what I did?
Hi! If you copy entire worksheet, the macro code will be copied along with the data and will work. If you copy the data to a new blank worksheet, you need to set the code on that new worksheet as described in the article above.
Hi there -- I'm so grateful for this code and your straightforward instructions! I'm having a small issue. The code works perfectly on my first worksheet but not on my second worksheet. I've copied and pasted the same code from my first to my second but I don't get the multi-selection functionality. Is there something in the code that needs to change from one worksheet to the next? These are 2 sheets in the same Excel file (workbook). Much appreciated!
Hi! When inserting the code into the second sheet, you do not need to change anything in the code. If multiple selection does not work, then the code is inserted incorrectly.
Hi, for some reason I cannot get the multiple-selection options to work (even when I download the example docs that you have linked). Is there some setting in Excel that would prevent this option from working? Or is there a specific key that needs to also be pressed for multiple selections when you are in the dropdown (I tried doing control, that did not work).
Hi! You may have macros in Excel disabled. Maybe this article will be helpful: How to enable and disable macros in Excel.
Is there a way to share the file with others that has multiple selection so that they can edit the sheet?
Hi! There are two ways to share a macro in Excel - you can either send the workbook with macros enabled or the file containing the macro code. The recipient can then open the workbook or import the code file to utilize the macro. However, it is important to note that this approach may not be successful if the recipient has varying security settings or Excel versions.
Hello! Thank you for this info. I have a formula that attributes a monetary value to each selection of my drop down menu. Is there a way I can keep these value associations even with multiple selections? For example, If you choose "Party package A" from the drop down menu in Column F, then it will add $200 in column G. However if a person chose "Party Package A" along with "Balloon Garland", I'd like column G to total both the values of "Party package A" and "Balloon Garland"
Hi! This depends on the formula you use in column G. The multiple selection macro creates a text string in column F of all the values you selected in the drop-down list.
Now I got the problem that my other Formulars not work. How can I fix that I need them.
The multiple selections macro only works in cells that have a drop-down list. It cannot affect your formulas.
Only wanted to say thank you Alex for sharing with the rest of the world. This tutorial was extensive and included all possible variations for the same problem.