Solved

excel vb macro valuelist multiple values

Posted on 2014-04-18
5
181 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now