Depositing ListBox Values Into Active Cell?

D

Daystrom

Probably this is a stupid question, but the closest answer I can find
anywhere is Debra Dagleish's code that allows for consecutive selections from
a data-validation dropdown to be entered in a cell, separated by commas. For
a few reasons I'd rather do something with a ListBox in a UserForm.

On the UserForm is a ListBox (called ListBox2) which can contain any number
of items. When a user clicks a button on the UserForm, is it possible to have
those items, separated by commas, deposited into the Active Cell on the
current worksheet?

If anyone could help, I'd really appreciate it. I keep finding close
alternatives to what I need, but nothing that quite hits it, and I'm clearly
I'm just not smart enough to do this.
 
C

Chip Pearson

Try


Private Sub CommandButton2_Click()
Dim N As Long
Dim S As String
With Me.ListBox1
If .ListCount = 0 Then
Exit Sub
End If
For N = 0 To .ListCount - 1
S = S & .List(N) & ","
Next N
End With
S = Mid(S, 1, Len(S) - 1)
ActiveCell.Value = S
End Sub



Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
D

Daystrom

You're a god, Chip! It works perfectly--thank you so much! Sorry about the
slow replay, but I had to leave work early yesterday to visit (horribly) with
my parents in law, so I just saw this. You've made this whole weekend much
better. Again, thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top