Drop-down list with multiple entries in a single cell

Innoguide

Board Regular
Joined
Sep 13, 2011
Messages
159
Is there anyway, I can create a drop down list that allows users to choose items from a list and place them into a single cell with comma separation (e.g. Rome, New York, Rio Di Janero)

If I could limit it to one item per cell, a simple drop down data validation list would work, but I need to limit entry to 1 cell/column.

Any suggestions would be much appreciated.
 
Code:
Private Sub CommandButton1_Click()

    Dim i As Long, strTemp As String
    With ListBox1
        'Read selections
        For i = 0 To .ListCount - 1
            If .Selected(i) Then
                strTemp = strTemp & .List(i) & MySeperator
                .Selected(i) = False    ' Clear selections
            End If
        Next i
    End With
    If Len(strTemp) Then
        strTemp = Left(strTemp, Len(strTemp) - Len(MySeperator))
        ActiveCell.Value = strTemp
    [COLOR="Red"]Else
        ActiveCell.ClearContents[/COLOR]
    End If
    
    UserForm1.Hide
    
End Sub


Also, this fixes another minor glitch...
Code:
Private Sub UserForm_Activate()
    'Match Listbox selections with ActiveCell selections
    Dim strCell As String, i As Long
    strCell = ActiveCell.Value & MySeperator
    With ListBox1
        For i = 0 To .ListCount - 1
            .Selected(i) = InStr(1, strCell, .List(i), 1)
        Next i
    End With
End Sub
 
Last edited:
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi AlphaFrog,

A related question for you from a new user. I used your code to allow for multiple entries in one of my dropdown lists (my cell "Q8") but I'd like to be able to do the same for another two dropdown lists (in cells "K11" and "K14"). Any suggestions for how to do this?

I'm new to VBA so I don't understand the code that well but I was thinking that if I could make the dropdown list reference = Q8 or K11 or K14, that might work. Only problem is that it looks like the code does the opposite and says to not run the program for cells other than Q8 (I tried adding K11 and K14 in that line of the code to no avail).

Thanks!




You could create a UserForm that has a multi-selects listbox. The UserForm could be triggered when the user select a specific cell or clicks a button.

This code will concatenate multiple selections from a Data Validation dropdown list (code source) in cell Q8.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim oldVal As String
    Dim newVal As String
    
    If Target.Address(0, 0) <> "[COLOR=Red]Q8[/COLOR]" Then Exit Sub

    On Error GoTo ReEnable
    Application.EnableEvents = False
    newVal = Target.Value
    Application.Undo
    oldVal = Target.Value
    Target.Value = newVal

    If oldVal <> "" And newVal <> "" Then
        Target.Value = oldVal & ", " & newVal
    End If
ReEnable:
    Application.EnableEvents = True
    
End Sub
 
Upvote 0
Hi cvande and welcome to the forum. Good job on searching for a solution first.

Try this...

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Worksheet_Change([color=darkblue]ByVal[/color] Target [color=darkblue]As[/color] Range)
    
    [color=darkblue]Dim[/color] oldVal [color=darkblue]As[/color] [color=darkblue]String[/color]
    [color=darkblue]Dim[/color] newVal [color=darkblue]As[/color] [color=darkblue]String[/color]
    
[B]    [color=darkblue]If[/color] Target.Count > 1 [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Sub[/color]
    [color=darkblue]If[/color] Intersect(Range("Q8,K11,K14"), Target) [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Sub[/color][/B]
    
    [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]GoTo[/color] ReEnable
    Application.EnableEvents = [color=darkblue]False[/color]
    newVal = Target.Value
    Application.Undo
    oldVal = Target.Value
    Target.Value = newVal
    
    [color=darkblue]If[/color] oldVal <> "" And newVal <> "" [color=darkblue]Then[/color]
        Target.Value = oldVal & ", " & newVal
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    
ReEnable:
    Application.EnableEvents = [color=darkblue]True[/color]
    [color=darkblue]If[/color] Err.Number <> 0 [color=darkblue]Then[/color] MsgBox Err.Description, vbCritical, "Error " & Err.Number
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Last edited:
Upvote 0
Hi AlphaFrog, I've been searching around for a few days now, and your topic has been very helpful. I'm pretty much stumped right now though and was hoping you were still subscribed to this topic!

I have written up a summary of my spreadsheet and what I'm trying to do:

Workbook has 2 sheets. Workbook is shared amongst a team of people who all have it open.

Sheet1 has 2 relevant columns(E & F). Sheet1 is a list of projects that each need to have a set of specific tasks completed from Task 1 to Task 19. Each task needs to be sequentially completed on each project, and I need to be able to look into each account and see that they have been completed (We also need to keep a history of what user has completed each task and on what date – but I believe the Excel Track Changes history log can accomplish this?)
- Column E uses your VB drop down method from this forum post to display a list of the 19 required tasks when a user clicks on the corresponding cell on Column E
- Column F from cell F3 downward (Infinitely, as new projects are pasted in to the bottom of the sheet) is filled with the deadline date of each project.

Sheet2 has a bunch of lists used elsewhere in the spreadsheet

The spreadsheet is using conditional formatting on the deadline dates to highlight the date based on how close today is to the deadline listed. The spreadsheet then also colour codes the project row based on the status of the task entry in Column E. I’m currently just using a normal dropdown list, but the problem is there is no way to easily look at an account and see that a user has checked off the other prior tasks.

There are a few problems I’m running into, as I am completely new to VB:
- The only way I could get the “list entries” to show up on the list was to paste them way over in Column P of Sheet1
o It would be preferred to have the list on Sheet2, where there is a summary of other functional lists
- The current way the list works is everything that gets selected will concatenate in the cell, causing the colour coding for the project to fail (The conditional formatting is currently set up to look for a specific entry for example: =$E3="File Complete")
o Is there a way to make the dropdown list prioritize the list in a certain way, so when a higher level task has been clicked it will be displayed over any lower level, but still show that the other tasks <19 have been clicked (As in they are still highlighted/checked off when the user clicks on the E Cell)
- The main reason I wanted to use your method for the list instead of just a normal drop down, is because we need to be able to be able to audit the projects and see that people have been completing their tasks. Do you think there is an easier way to do this? I was thinking there might be a way to just use the normal drop down and try to figure out a way to update a log that would show a user changed a project’s task status from X to Y on Z date?

See below for the VB code I'm using:
UserForm1
Code:
Private Sub UserForm_Initialize()
 
    With ListBox1
        .List = Range("P3:P21").Value    'Range of cells with the list of tasks
        .MultiSelect = fmMultiSelectMulti
    End With
   
    UserForm1.Caption = "Select Completed Tasks"
    CommandButton1.Caption = "Okay"
   
End Sub
Private Sub CommandButton1_Click()
 
    Dim i As Long, strTemp As String
    With ListBox1
        'Read selections
        For i = 0 To .ListCount - 1
            If .Selected(i) Then
                strTemp = strTemp & .List(i) & MySeperator
                .Selected(i) = False    ' Clear selections
            End If
        Next i
    End With
    If Len(strTemp) Then
        strTemp = Left(strTemp, Len(strTemp) - Len(MySeperator))
        ActiveCell.Value = strTemp
    Else
        ActiveCell.ClearContents
    End If
   
    UserForm1.Hide
   
End Sub
Private Sub UserForm_Activate()
    'Match Listbox selections with ActiveCell selections
    Dim strCell As String, i As Long
    strCell = ActiveCell.Value & MySeperator
    With ListBox1
        For i = 0 To .ListCount - 1
            .Selected(i) = InStr(1, strCell, .List(i), 1)
        Next i
    End With
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    'Hide userform if Close "X" clicked
    If CloseMode = 0 Then
        Cancel = True
        Me.Hide
    End If
    
End Sub

Sheet1
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count = 1 Then
        'Range of cells to have the pop-up userform
        If Not Intersect(Range("E3:E1000"), Target) Is Nothing Then
            UserForm1.Show
        End If
    End If
End Sub
 
Upvote 0
Hi HelpVBFrog and welcome to the forum. Well done on searching for a solution first.

This is the first time I've seen anyone creating a specific forum moniker to illicit help. That doesn't score you any extra empathy points... well maybe 1/2 a point :)

It's a little tricky following your description. There's a lot there. Perhaps if you uploaded an example workbook to a file share site (dropbox.com, mediafire.com) and post the link here, I'll take a look at it. This is not an invitation for others that read this thread to do the same. I don't want to do your project for you, but you've done some solid work here and explained it fairly well. I think most of your questions may be relatively simple to answer but for a better understanding. You could strip out any non-related data, formatting, or code if you want, and add notes if needed. I don't care what it looks like as long as it describes what you are trying to accomplish.

One quick answer:
- The only way I could get the “list entries” to show up on the list was to paste them way over in Column P of Sheet1
You can reference a range on a different worksheet like this...
Code:
    With ListBox1
        .List = [B]Sheets("Sheet2").[/B]Range("P3:P21").Value    'Range of cells with the list of tasks
        .MultiSelect = fmMultiSelectMulti
    End With
 
Upvote 0
Well that was an unexpectedly speedy reply! I couldn't think of a catchy username, so I used what came to mind hahahahaha.

AlphaFrog Project Spreadsheet

Here is a link to an example spreadsheet. The password to the zip is "AFrog". I have filled it with some random projects and dates as well as some example combinations of tasks. Hopefully my description of what I'm trying to do makes a little more sense with a visual to poke around in.

Thank you for that quick fix for the task list!
 
Upvote 0
Maybe next time try "catchy username" as a catchy username.

I got the file.

If each selected task is color coded, what color to you want the row when multiple tasks are selected. It may be easier for the code to color the row when you select Okay rather than Conditional Formatting, but I don't follow what how you want it colored.

I don't understand what task has priority? Do you mean list the selected tasks in reverse order; Task 19 first and Task1 last ?

Is that the only two problems?
 
Upvote 0
I figured something like "catchy username" would have been taken hahaha.

As for the colour coding, the tasks that are selected are tasks that have been completed so the way I was trying to get the colour coding to work was by colouring the "highest level" task. So for example, if the user is now working on task 4, they would have task 1 2 and 3 selected. The current highest level task for that project would be task 3. If we were to click on the dropdown column for that project we would see task 1 2 and 3 highlighted, but I want the cell to only be showing task 3 as the output. If I could get it to work that way, then the normal conditional formatting I have set up already would then activate and colour the entire row for the project to "Task 3 complete" colour.

In regards to the prioritizing, I was trying to figure out how to word the above way of outputting Task 3, instead of it showing Task1Task2Task3.

I hope I'm describing this correctly!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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