Forum Discussion
Selecting multiple items from a dropdown list and returning different values
- 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
I hope it helps you, so I kindly ask you it this is your solution,please hit the like button and mark it as solved.
Sub OutputFromMultiSelectListBox()
Dim LoopIndex As Integer
Dim OutputList As String
For LoopIndex = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(LoopIndex) Then
OutputList = OutputList & ListBox1.List(LoopIndex) & vbCrLf
End If
Next LoopIndex
MsgBox "Selected items are:" & vbCrLf & OutputList
End Sub
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-PetrukioSep 02, 2021Bronze ContributorI 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/- 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.