Forum Discussion
Charlie_The_Connector
Apr 26, 2023Copper Contributor
Dropdown list with multiple selection in cell
I have a item list in sheet 1 of work book, A2 to A47 I would be adding more items to this list. On sheet 2 I have 7 columns A to G which I will have A (name), B (surname), C (mobile), D (email), E (...
NikolinoDE
Apr 26, 2023Gold Contributor
You can use VBA code to create a dropdown list with multiple selections in a cell. Here is an example of VBA code that you can use to achieve this:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$F$2" Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
This code will allow you to select multiple items from the dropdown list in cell F2 by separating them with a comma. You can modify the code to fit your specific needs.
After also creating a dropdown menu, you can use this code to select multiple items from the dropdown list in cell F2 by separating them with a comma. You can adapt the code to your specific needs.
Attached is an example file where you can test the function.
Hope it will help you in your project!
mm_anc
Mar 28, 2024Copper Contributor
Hello, Is there a way to do this in a table? In the example above, the target address is a single cell. Can this be applied to a column in a table?
Thanks!
Thanks!
- peiyezhuMar 28, 2024Bronze Contributor
Have you tried the file I have uploaded ?
I guess it do apply to a column.