Solved

excel vb macro valuelist multiple values

Posted on 2014-04-18
5
185 Views
Last Modified: 2014-04-27
folks

I would like my sheet 1 column c be able to choose from a valuelist but allow to select multiple values to the cell , also, would like to have a comma between each value select and no duplications allow i.e

C
car,house,bike
car,house
bike

also, would like the formula /code be applicable to all rows in this column

keen for your guidance
0
Comment
Question by:rutgermons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 40009329
You want to have a single cell fill with text (multiple values having comma separation) when you select those text values from a list in a control?
0
 

Author Comment

by:rutgermons
ID: 40009360
yep!
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 40009748
If you use an ActiveX Listbox (ListBox1) and add the following VBA code to the Sheet it belongs to, you should get the desired results.  Note: I have placed my listbox data in sheet2 column A (rows 1 through 7).  Also, I'm placing the resulting string in cell J7.

Private Sub ListBox1_Change()
Dim selItems As String
    selItems = ""
    
    Cells(7, 10) = "" 'initialize
    
    For i = 0 To Me.ListBox1.ListCount - 1
        If Me.ListBox1.Selected(i) = True Then
            selItems = selItems & Me.ListBox1.List(i) & ", "
        End If
    Next
    
    Cells(7, 10) = selItems
End Sub



Private Sub Worksheet_Activate()
    Me.ListBox1.ListFillRange = "'Sheet2'!A1:A7"
    Cells(7, 10) = ""
End Sub

Open in new window

0
 

Author Comment

by:rutgermons
ID: 40010677
dave

thanks for this, it works but i can't see it add multiple ,selects to the field?

can u share me your sheet perhaps?

cheers
0
 
LVL 15

Accepted Solution

by:
David L. Hansen earned 500 total points
ID: 40012534
This line: selItems = selItems & Me.ListBox1.List(i) & ", "
concatenates the multiple selections into one string.  If you make your column wider or turn on text wrapping you will see the multiples being displayed.  Also, change your target cell from "Cells(7, 10)" to whatever works best for you.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question