To create a multiple selection drop down in Excel, you must use a VBA Worksheet_Change event macro because standard Data Validation only allows a single selection. By adding a script to the specific sheet module, you can instruct Excel to append new selections to the existing cell value rather than replacing them, typically separated by a comma or a new line.
What You'll Need
- Microsoft Excel installed on a Windows or Mac computer.
- A workbook saved in the .xlsm (Excel Macro-Enabled Workbook) format to ensure the code is preserved.
- A pre-defined list of items to serve as your drop-down options.
- Basic access to the Visual Basic for Applications (VBA) editor.
Step-by-Step
- Prepare Your Data Validation List: Before adding code, create your standard drop-down. Select the cell or range of cells where you want the multiple selections to occur. Go to the Data tab, select Data Validation, choose "List" from the Allow menu, and select the range containing your options or type them manually separated by commas. Click OK.
- Open the VBA Editor: Right-click on the sheet tab name at the bottom of your Excel window (e.g., "Sheet1"). Select "View Code" from the context menu. This opens the VBA editor directly to the module for that specific worksheet, which is critical because the code must be a worksheet event, not a standard module.
- Insert the Macro Code: Copy and paste the following code into the white code window. Ensure the dropdowns at the top of the window are set to "Worksheet" on the left and "Change" on the right.
Private Sub Worksheet_Change(ByVal Target As Range) Dim Oldvalue As String Dim Newvalue As String On Error GoTo Exitsub ' Check if the change happened in a cell with data validation If Target.Count > 1 Then Exit Sub If Target.Validation.Type = 3 Then Application.EnableEvents = False Newvalue = Target.Value Application.Undo Oldvalue = Target.Value Target.Value = Newvalue If Oldvalue < "" Then ' Do nothing if the cell was empty ElseIf Newvalue = "" Then ' Do nothing if the cell was cleared ElseIf InStr(1, Oldvalue, Newvalue) > 0 Then ' Optional: Remove the value if it is already selected If InStr(1, Oldvalue, " " & Newvalue) > 0 Then Target.Value = Replace(Oldvalue, " " & Newvalue, "") ElseIf InStr(1, Oldvalue, Newvalue & " ") > 0 Then Target.Value = Replace(Oldvalue, Newvalue & " ", "") Else Target.Value = Replace(Oldvalue, Newvalue, "") End If Else Target.Value = Oldvalue & ", " & Newvalue End If End If Exitsub: Application.EnableEvents = True End Sub - Customize the Separator: In the code provided, look for the line
Target.Value = Oldvalue & ", " & Newvalue. If you prefer the selections to appear on new lines within the same cell instead of being separated by commas, change ", " tovbCrLf. If you do this, you must also select the cells in your worksheet and enable "Wrap Text" in the Home tab for the line breaks to be visible. - Save the Workbook: Close the VBA editor window. Go to File > Save As and change the file extension to "Excel Macro-Enabled Workbook (*.xlsm)". If you save it as a standard .xlsx file, all your VBA code will be permanently deleted when you close the file.
- Test the Functionality: Click on your drop-down cell and select an item. Then, click the same cell again and select a different item. The second item should now appear next to the first one, separated by your chosen delimiter.
Common Mistakes
One of the most frequent errors is placing the code in a standard Module (Insert > Module) instead of the Sheet Module. Worksheet_Change is an event-driven procedure; it only triggers when a change is made to a cell on a specific sheet. If the code is in a general module, Excel will not know which sheet to monitor, and the macro will never run.
Another common mistake is forgetting to disable events. The line Application.EnableEvents = False is vital. Without it, when the macro changes the cell value to add the second selection, that change triggers the Worksheet_Change event again, creating an infinite loop that can cause Excel to freeze or crash. Always ensure that Application.EnableEvents = True is called at the end of the script, even if an error occurs, which is why the On Error GoTo Exitsub line is included.
Users often overlook the "Wrap Text" setting when using vbCrLf. If you use a carriage return as your separator but Wrap Text is disabled, Excel will display the values on one line with a small square symbol or a space where the break should be, making the data look corrupted when it is actually formatted correctly.
Tips
To limit this functionality to a specific range of cells rather than every single drop-down on the sheet, add a range check at the beginning of the code. For example, using If Intersect(Target, Range("A2:A10")) Is Nothing Then Exit Sub will ensure the multiple selection logic only applies to cells A2 through A10. This prevents the macro from running on other data validation lists in your sheet that are intended to remain single-selection.
If you want to prevent duplicate entries in your list, the InStr function used in the provided code is essential. It checks if the new selection already exists within the string of old values. You can modify this logic to either ignore the second click or, as shown in the example, remove the item if it is clicked again, effectively creating a "toggle" system for your selections.
For a cleaner look, use a named range for your data validation source. This makes it easier to update the list of options in the future without having to manually update the data validation settings for every cell in your worksheet.
Troubleshooting
If the drop-down is still only selecting one item and not appending, the most likely cause is that "Events" have been disabled. This happens if a previous run of the macro crashed before reaching the Application.EnableEvents = True line. To fix this, press Ctrl+G in the VBA editor to open the Immediate Window, type Application.EnableEvents = True and press Enter. Then try the drop-down again.
If you receive a "Type Mismatch" error, check if you have merged cells in your selection range. VBA often struggles with Target.Value when merged cells are involved. The best practice is to avoid merged cells in any range where macros are operating; use "Center Across Selection" in the Alignment settings instead.
If the macro is running too slowly, ensure that you do not have other heavy calculations or volatile functions (like OFFSET or INDIRECT) triggering every time a cell changes. You can wrap the logic in Application.Calculation = xlCalculationManual and set it back to xlCalculationAutomatic at the end of the script to improve performance on very large sheets.
Frequently Asked Questions
Will this work on Excel for the Web?
No, VBA macros do not run in the web version of Excel. You must open the file in the Excel Desktop Application for the multiple selection functionality to work.
Can I use this for checkboxes instead?
This code specifically modifies a Data Validation drop-down. While you can use checkboxes in Excel, they require a different approach involving Form Controls or ActiveX controls and separate VBA logic to link them to a cell.
How do I clear all selections in a cell?
You can simply select the cell and press the Delete key on your keyboard. The code is written to handle empty strings, so deleting the contents will not trigger an error or append empty values.
Does this work on Mac?
Yes, VBA is supported on Excel for Mac, though the VBA editor interface looks slightly different. The logic of the Worksheet_Change event remains the same.
Can I change the comma to a semicolon or a dash?
Yes. Simply locate the line Target.Value = Oldvalue & ", " & Newvalue and replace the ", " with any character or string of your choice, such as "; " or " - ".