Multiple Selections in Dropdown?

cmarie85

New Member
Joined
Apr 27, 2022
Messages
6
Office Version
  1. 2019
Platform
  1. Windows
Excel newbie here. I've seen a few threads on this but can't quite get it to work on my end. I originally used the code here: How to Make Multiple Selections in an Excel Drop-Down list and tried it on a test column. The only thing i changed was A2 in line 6 to Q2 to match my column. It worked perfectly! But my workbook has a total of 14 worksheets, each sheet has the exact same content (each sheet represents a different city in my case). So then I went in and repeated the data-validation in all sheets and then opened up the VBE editor and went sheet by sheet, posting that code into the VBE editor. Saved, exited. But now when I try to make multiple selections on any of the sheets, it doesn't work. I can only assume I did it wrong as far as having it apply to multiple sheets. But I just can't seem to figure it out. Help?

TLDR; I need to be able to make multiple selections in a single drop down list... on every sheet in my workbook.

VBA code used:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Not Intersect(Target, Range("Q2")) Is Nothing 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 & vbNewLine & Newvalue
         Else:
            Target.Value = Oldvalue
         End If
      End If
   End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
dropdowns are for single selection,
listboxes can do multiple

Use the right tool for the right job. don't use a screwdriver to hammer in nails.
 
Upvote 0
Put a break point at the start of the code and step thru (F8), watch the execution and check variable values after a line is executed. Can also check what your target values are. For all you know, your list may be in the wrong cell. BTW, doesn't work doesn't help much. :)
Can't say I totally disagree with the listbox comment, but sometimes solving a code problem teaches you something.
 
Upvote 0
Put a break point at the start of the code and step thru (F8), watch the execution and check variable values after a line is executed. Can also check what your target values are. For all you know, your list may be in the wrong cell. BTW, doesn't work doesn't help much. :)
Can't say I totally disagree with the listbox comment, but sometimes solving a code problem teaches you something.

My apologies. "Doesn't work" in my case means I can only choose one selection at a time in the dropdown menu. When I say I'm a newbie at excel, oh boy I mean I know next to nothing. I know even less about listboxes than I do dropdowns. Maybe someone can point me to the best option?

Here's the deal. I track incidents for a child welfare agency. Some incidents result in an Abuse/Neglect finding, some don't. So as you can see in my excel below, I need to be able to mark n/a or mark which type of Abuse/Neglect was investigated. In some cases, there's only one - which is perfect as I can simply select one option. But in SOME cases, there are more than one type of A/N investigated so I need to be able to mark multiple options. And this is a list I track throughout the year so I'm always adding incidents - so that one Abused/Neglect column needs to be able to continue to grow and always have that same multiple select option.

Hopefully I explained that well. ? I'm a total novice when it comes to this stuff but i'm just trying to make my spreadsheet as efficient as possible. So if anyone can help or has a better idea, I'd really appreciate it!


Investigations - 2022.xlsm
ABCDEFGHI
1OfficeDateFamilyTypeInvest #Original AllegationFindings Letter entered -dateAbuse/Neglect Findings
2SA6/24/21Doe, FamilySAMPn/an/a6/25/21n/a
3SA7/27/21Doe, FamilyHM Sampn/an/a7/27/21n/a
4SAUnkDoe, FamilyRCCL2765956Supervision7/29/21n/a
5SAUnkDoe, FamilyRCCL2761134Discipline8/2/21n/a
6SAUnkDoe, FamilyRCCL2766099Environment8/2/21n/a
7SA8/6/21Doe, FamilySAMPn/an/a8/11/21n/a
8SA8/12/21Doe, FamilySAMPn/an/a8/12/21n/a
9SA8/19/21Doe, FamilySAMPn/an/a8/20/21n/a
10SA8/28/21Doe, FamilySAMPn/an/a8/30/21n/a
11SAUnkDoe, FamilyRCCL2774480Supervision9/10/21NegSup No
12SA8/10/21Doe, FamilyRCCL2773251Supervision9/24/21n/a
13SAUnkDoe, FamilyRCCL2789944Supervision10/18/21n/a
14SA11/1/21Doe, FamilyHM Sampn/an/a11/1/21n/a
15SAUnkDoe, FamilyRCCL2802200Supervision11/5/21NegSup No
16SA11/22/21Doe, FamilyHM Sampn/an/a11/22/21n/a
17SA11/23/21Doe, FamilyMONIn/an/a11/23/21n/a
18SA12/1/21Doe, FamilyHM Monin/an/a12/1/21n/a
19SAUnkDoe, FamilyRCCL2821235Supervision12/2/21n/a
20SAUnkDoe, FamilyRCCL2814335Discipline12/6/21SxAb No
21SAUnkDoe, FamilyRCCL2821803Supervision1/18/22PhAb No
22SAUnkDoe, FamilyRCCL2829853Supervision1/24/22PhAb No
23SAUnkDoe, FamilyRCCL2833019SIR1/25/22n/a
24SAUnkDoe, FamilyRCCL2822326Supervision1/28/22n/a
25SAUnkDoe, FamilyRCCL2848391SxAb2/17/22SxAb No
26SAUnkDoe, FamilySAMPn/an/a2/18/22n/a
27SA2/22/22Doe, FamilySAMPn/an/a2/25/22n/a
28SAUnkDoe, FamilyRCCL2864618SIR3/8/22n/a
29SA3/17/22Doe, FamilyHM Sampn/an/a3/17/22n/a
30SA4/13/22Doe, FamilyHM Sampn/an/a4/13/22NegSup No*PhAb No
31SA4/13/21Doe, FamilyMONIn/an/aNeedn/a
32SAUnkDoe, FamilyRCCL2764149SupervisionNeedn/a
33SAUnkDoe, FamilyRCCL2818776NeedNeedn/a
34SA12/28/21Doe, FamilySAMPn/an/aNeedNegSup No
35SAUnkDoe, FamilyRCCL2832480SupervisionNeedn/a
6 SA (2)
Cells with Data Validation
CellAllowCriteria
H1:H35Listn/a, PhAb Yes, PhAb No, SxAb Yes, SxAb No, EmAb Yes, EmAb No, NegSup Yes, NegSup No, MedNeg Yes, MedNeg No
D:DListRCCL,SAMP,MONI,HM Samp,HM Moni
E:ECustom=OR(COUNTIF($E$1:$E$9878,E1)=1,E1="n/a")
A1:A35ListAma,Bville,Bwd,Burl,CC,Dal,ELP,Hou,MC,RR,SA,Ty,Vic,WF
 
Upvote 0
"Doesn't work" in my case means I can only choose one selection at a time in the dropdown menu.
That code strings together multiple single selections and separates them with linefeeds. It's not a multi-select combo. There is no such thing in Access (unless the combo is based on a multi value field, which I'd say most db developers avoid) so I doubt it can behave any different in Excel either. Thus I can't see how you can say it ever worked as a multi select combo.

What I also see as problematic in that code is that if you have previously chosen a value like 15 (or 150 for example), you will not be able to pick 1. That might not be a limitation for you. Maybe it's doing what you want but you can't see the added values because of your row heights for rows with multiple selections? A listbox won't fix that either.
 
Upvote 0
After some searching on this forum, I found a different VBA code that works.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'Code by Sumit Bansal from https://trumpexcel.com
' To make mutliple selections in a Drop Down List in Excel

Dim Oldvalue As String
Dim Newvalue As String

On Error GoTo Exitsub
If Target.Address = "$H$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
            Target.Value = Oldvalue & ", " & Newvalue
        End If
    End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub

The only 'problem' now is that it ONLY works with a single cell in the column. I'm assuming this is because of the "$H$2" part. So how can I edit this code so that it works for the rest of the column? Including mini sheet so you can see that in cell H2, I was able to make multiple selections. But I could only make one selection in, for example, cell H4.

Investigations - 2022.xlsm
ABCDEFGH
1OfficeDateFamilyTypeInvest #Original AllegationFindings Letter entered -dateAbuse/Neglect Findings
2SA6/24/21Doe, FamilySAMPn/an/a6/25/21PhAb Yes, SxAb No, EmAb No
3SA7/27/21Doe, FamilyHM Sampn/an/a7/27/21n/a
4SAUnkDoe, FamilyRCCL2765956Supervision7/29/21SxAb No
5SAUnkDoe, FamilyRCCL2761134Discipline8/2/21n/a
6SAUnkDoe, FamilyRCCL2766099Environment8/2/21n/a
7SA8/6/21Doe, FamilySAMPn/an/a8/11/21n/a
8SA8/12/21Doe, FamilySAMPn/an/a8/12/21n/a
9SA8/19/21Doe, FamilySAMPn/an/a8/20/21n/a
6 SA (2)
Cells with Data Validation
CellAllowCriteria
H1:H9Listn/a, PhAb Yes, PhAb No, SxAb Yes, SxAb No, EmAb Yes, EmAb No, NegSup Yes, NegSup No, MedNeg Yes, MedNeg No
D:DListRCCL,SAMP,MONI,HM Samp,HM Moni
E:ECustom=OR(COUNTIF($E$1:$E$9878,E1)=1,E1="n/a")
A1:A9ListAma,Bville,Bwd,Burl,CC,Dal,ELP,Hou,MC,RR,SA,Ty,Vic,WF
 
Upvote 0
Target.Value = Oldvalue & ", " & Newvalue
That's one idea I had in mind when I pointed out the issues. Other was to have the code autosize the row.
Try "H:H" rather than H2. You have applied data validation to the column/range?
e.g.
Select that range, ribbon data tab>Data Tools group>validation, choose the list range to add the list values>OK
otherwise you'll be able to type in anything.
 
Upvote 0
Just in case anyone was watching this thread for an answer, I finally got it. I changed it from "Target.Address = "$H$2" to "Target.Column = 8"

This allows multiple selections in a drown down, in a whole column.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'Code by Sumit Bansal from https://trumpexcel.com
' To make mutliple selections in a Drop Down List in Excel

Dim Oldvalue As String
Dim Newvalue As String

On Error GoTo Exitsub
If Target.Column = 8 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
            Target.Value = Oldvalue & ", " & Newvalue
        End If
    End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub

Investigations - 2022.xlsm
ABCDEFGH
1OfficeDateFamilyTypeInvest #Original AllegationFindings Letter entered -dateAbuse/Neglect Findings
2SA6/24/21Doe, FamilySAMPn/an/a6/25/21PhAb Yes, SxAb No, EmAb No
3SA7/27/21Doe, FamilyHM Sampn/an/a7/27/21SxAb No
4SAUnkDoe, FamilyRCCL2765956Supervision7/29/21SxAb No
5SAUnkDoe, FamilyRCCL2761134Discipline8/2/21n/a, PhAb Yes, PhAb No
6SAUnkDoe, FamilyRCCL2766099Environment8/2/21n/a
7SA8/6/21Doe, FamilySAMPn/an/a8/11/21n/a
8SA8/12/21Doe, FamilySAMPn/an/a8/12/21n/a
9SA8/19/21Doe, FamilySAMPn/an/a8/20/21n/a
10SA8/28/21Doe, FamilySAMPn/an/a8/30/21n/a
11SAUnkDoe, FamilyRCCL2774480Supervision9/10/21EmAb Yes, NegSup Yes
6 SA (2)
Cells with Data Validation
CellAllowCriteria
H1:H11Listn/a, PhAb Yes, PhAb No, SxAb Yes, SxAb No, EmAb Yes, EmAb No, NegSup Yes, NegSup No, MedNeg Yes, MedNeg No
D:DListRCCL,SAMP,MONI,HM Samp,HM Moni
E:ECustom=OR(COUNTIF($E$1:$E$9878,E1)=1,E1="n/a")
A1:A11ListAma,Bville,Bwd,Burl,CC,Dal,ELP,Hou,MC,RR,SA,Ty,Vic,WF
 
Upvote 0
Solution

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top