Forum Discussion
DDBDS
Sep 01, 2021Copper Contributor
Selecting multiple items from a dropdown list and returning different values
I've seen VBA code that will allow one to select multiple items from a drop-down list. I've seen VBA code that allow you to create a drop down list and return a different value. What I need is a co...
- Sep 02, 2021
Find attached and the code below as well.
Private Sub Worksheet_Change(ByVal Target As Range) Dim Oldvalue As String Dim Newvalue As String Dim selectedNum As Variant Application.EnableEvents = True On Error GoTo Exitsub If Target.Column = 3 Then If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then GoTo Exitsub Else: If Target.Value = "" Then GoTo Exitsub Else Application.EnableEvents = False Newvalue = Target.Value selectedNum = Application.VLookup(Newvalue, ActiveSheet.Range("dropdown"), 2, False) Newvalue = selectedNum 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
DDBDS
Sep 01, 2021Copper Contributor
Juliano-Petrukio thanks for the reply. I added your suggested code but it didn't appear to change anything. Currently I have a piece of code that was supplied by ExtendOffice that I found while researching. This code provides the code utilizing vlookup. If I could get it to allow multiple selections, that would be the end goal.
Private Sub Worksheet_Change(ByVal Target As Range)
selectedNa = Target.Value
If Target.Column = 3 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("dropdown"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub
Juliano-Petrukio
Sep 02, 2021Bronze Contributor
I thought it was a userform control.
Anyway, read the following article.
Surely it will help you.
https://trumpexcel.com/select-multiple-items-drop-down-list-excel/
Anyway, read the following article.
Surely it will help you.
https://trumpexcel.com/select-multiple-items-drop-down-list-excel/
- DDBDSSep 02, 2021Copper ContributorYep, that is the other half of the code but I can't seem to successfully combine the two in order to achieve the desired outcome.
- Juliano-PetrukioSep 02, 2021Bronze ContributorShare your spreadsheet or a sample File só we can try to help you more.
- DDBDSSep 02, 2021Copper ContributorAdded. Thank you.