SOLVED

Selecting multiple items from a dropdown list and returning different values

%3CLINGO-SUB%20id%3D%22lingo-sub-2708799%22%20slang%3D%22en-US%22%3ESelecting%20multiple%20items%20from%20a%20dropdown%20list%20and%20returning%20different%20values%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2708799%22%20slang%3D%22en-US%22%3E%3CP%3EI've%20seen%20VBA%20code%20that%20will%20allow%20one%20to%20select%20multiple%20items%20from%20a%20drop-down%20list.%26nbsp%3B%20I've%20seen%20VBA%20code%20that%20allow%20you%20to%20create%20a%20drop%20down%20list%20and%20return%20a%20different%20value.%26nbsp%3B%20What%20I%20need%20is%20a%20combination%20of%20the%20two.%26nbsp%3B%20I%20want%20to%20present%20a%20user%20with%20a%20logical%20list%20of%20choices%20I.e.%20Living%20Room%2C%20Sun%20Room%2C%20Dining%20Room%2C%20etc.%20and%20allow%20them%20to%20select%20more%20than%20one.%26nbsp%3B%20The%20list%20would%20show%20the%20full%20name%20but%20return%20the%20abbreviation(s)%20of%20the%20list%20items%20selected.%26nbsp%3B%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDrop%20Down%20List%3C%2FP%3E%3CTABLE%20width%3D%22215%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%22135%22%3EAll%3C%2FTD%3E%3CTD%20width%3D%2280%22%3EALL%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22135%22%3ELiving%20Room%3C%2FTD%3E%3CTD%20width%3D%2280%22%3ELR%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22135%22%3ESun%20Room%3C%2FTD%3E%3CTD%20width%3D%2280%22%3ESR%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22135%22%3EDining%20Room%3C%2FTD%3E%3CTD%20width%3D%2280%22%3EDR%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22135%22%3EKitchen%3C%2FTD%3E%3CTD%20width%3D%2280%22%3EK%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22135%22%3EKitchen%20Pantry%3C%2FTD%3E%3CTD%20width%3D%2280%22%3EKP%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22135%22%3EBreakfast%20Room%3C%2FTD%3E%3CTD%20width%3D%2280%22%3EKB%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22135%22%3EFoyer%3C%2FTD%3E%3CTD%20width%3D%2280%22%3EF%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EReturned%20Values%3A%3C%2FP%3E%3CP%3ELR%2C%20DR%2C%20K%2C%20KB%3C%2FP%3E%3CP%3EK%2C%20F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHas%20anyone%20come%20across%20code%20that%20would%20accomplish%20this%20or%20have%20any%20suggestions.%26nbsp%3B%20As%20I%20mentioned%20I've%20found%20VBA%20code%20that%20does%20one%20or%20the%20other%20but%20not%20the%20combination.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2708799%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2709038%22%20slang%3D%22en-US%22%3ERe%3A%20Selecting%20multiple%20items%20from%20a%20dropdown%20list%20and%20returning%20different%20values%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2709038%22%20slang%3D%22en-US%22%3E%3CP%3EI%20hope%20it%20helps%20you%2C%26nbsp%3B%20so%20I%20kindly%20ask%20you%20it%20this%20is%20your%20solution%2Cplease%20hit%20the%20like%20button%20and%20mark%20it%20as%20solved.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESub%20OutputFromMultiSelectListBox()%0A%20%20%20Dim%20LoopIndex%20As%20Integer%0A%20%20%20Dim%20OutputList%20As%20String%0A%20%20%20For%20LoopIndex%20%3D%200%20To%20ListBox1.ListCount%20-%201%0A%20%20%20%20%20%20If%20ListBox1.Selected(LoopIndex)%20Then%0A%20%20%20%20%20%20%20%20%20OutputList%20%3D%20OutputList%20%26amp%3B%20ListBox1.List(LoopIndex)%20%26amp%3B%20vbCrLf%0A%20%20%20%20%20%20End%20If%0A%20%20%20Next%20LoopIndex%0A%20%20%20MsgBox%20%22Selected%20items%20are%3A%22%20%26amp%3B%20vbCrLf%20%26amp%3B%20OutputList%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1143816%22%20target%3D%22_blank%22%3E%40DDBDS%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2709184%22%20slang%3D%22en-US%22%3ERe%3A%20Selecting%20multiple%20items%20from%20a%20dropdown%20list%20and%20returning%20different%20values%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2709184%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F767933%22%20target%3D%22_blank%22%3E%40Juliano-Petrukio%3C%2FA%3E%26nbsp%3Bthanks%20for%20the%20reply.%26nbsp%3B%20I%20added%20your%20suggested%20code%20but%20it%20didn't%20appear%20to%20change%20anything.%26nbsp%3B%20Currently%20I%20have%20a%20piece%20of%20code%20that%20was%20supplied%20by%20ExtendOffice%20that%20I%20found%20while%20researching.%26nbsp%3B%20This%20code%20provides%20the%20code%20utilizing%20vlookup.%26nbsp%3B%20If%20I%20could%20get%20it%20to%20allow%20multiple%20selections%2C%20that%20would%20be%20the%20end%20goal.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20selectedNa%20%3D%20Target.Value%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20If%20Target.Column%20%3D%203%20Then%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BselectedNum%20%3D%20Application.VLookup(selectedNa%2C%20ActiveSheet.Range(%22dropdown%22)%2C%202%2C%20False)%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BIf%20Not%20IsError(selectedNum)%20Then%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Target.Value%20%3D%20selectedNum%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BEnd%20If%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BEnd%20If%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2710000%22%20slang%3D%22en-US%22%3ERe%3A%20Selecting%20multiple%20items%20from%20a%20dropdown%20list%20and%20returning%20different%20values%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2710000%22%20slang%3D%22en-US%22%3EI%20thought%20it%20was%20a%20userform%20control.%3CBR%20%2F%3EAnyway%2C%20read%20the%20following%20article.%3CBR%20%2F%3ESurely%20it%20will%20help%20you.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftrumpexcel.com%2Fselect-multiple-items-drop-down-list-excel%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ftrumpexcel.com%2Fselect-multiple-items-drop-down-list-excel%2F%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

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 combination of the two.  I want to present a user with a logical list of choices I.e. Living Room, Sun Room, Dining Room, etc. and allow them to select more than one.  The list would show the full name but return the abbreviation(s) of the list items selected.   

 

Drop Down List

AllALL
Living RoomLR
Sun RoomSR
Dining RoomDR
KitchenK
Kitchen PantryKP
Breakfast RoomKB
FoyerF

 

Returned Values:

LR, DR, K, KB

K, F

 

Has anyone come across code that would accomplish this or have any suggestions.  As I mentioned I've found VBA code that does one or the other but not the combination.

 

Thanks. 

8 Replies

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

@DDBDS 

@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

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/

Yep, 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.
Share your spreadsheet or a sample File só we can try to help you more.
best response confirmed by DDBDS (Occasional Contributor)
Solution

 

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