troubleshooting Question

Multi-select dropdown list in Excel - how to extend VB script to work on additional columns?

Avatar of evibesmusic
evibesmusicFlag for United States of America asked on
VB Script
2 Comments1 Solution26 ViewsLast Modified:

I'm NOT a VB developer and am trying to extend a code snippet I found online. The following code allows me to convert a standard dropdown menu into one that allows multiple selections. As each additional selection is made using the dropdown menu, the script appends each value separated by a comma.

The code works for column 5 of my spreadsheet and its dropdowns. However, I can't figure out how to alter the code to work for another column - say column 7 - that has dropdowns as well?

I tried copying and pasting the entire piece of code and simply updating the "Worksheet_Change()" class name and changing the reference to column 5 to column 7 but that didn't work.

Any suggestions?

Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from
' To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Column = 5 Then
  If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
    GoTo Exitsub
  Else: If Target.Value = "" Then GoTo Exitsub Else
    Application.EnableEvents = False
    Newvalue = Target.Value
    Oldvalue = Target.Value
      If Oldvalue = "" Then
        Target.Value = Newvalue
        If InStr(1, Oldvalue, Newvalue) = 0 Then
            Target.Value = Oldvalue & ", " & Newvalue
        Target.Value = Oldvalue
      End If
    End If
  End If
End If
Application.EnableEvents = True
Application.EnableEvents = True
End Sub

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros