-
Multiselect listbox values to a textbox
Hi all,
need help with writing multiselected values in a listbox to a userform text box. Have multi select working however it is only writing 1 value
eg
name1
name2
name3
name4
to a textbox as name1, name3, name4
this is a variation of what I had, however this only puts the first name on the list in the text box.
A previous version put the first selected name now im lost
[VBA]Private Sub CommandButton1_Click()
Dim Item As Long
Item = 1
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
UserForm1.TextBox4 = ListBox1.List(lItem)
ListBox1.Selected(Item) = False
End If
Next i
End Sub[/VBA]
Cheers
-
Build a string. Put the contents of the textbox into a string and then do your loop. IF the string is <> "" for the first loop then concatenate vblf and then concatenate the listbox item selected in the loop. After looping, add the string to the textbox.
-
or:
[VBA]
Private Sub Commancbutton1_Click()
sn = lijst.List
For j = 0 To UBound(lijst.List) - 1
If Not lijst.Selected(j) Then sn(j + 1, 0) = "~"
Next
TextBox1.Text = Join(Filter(Application.Transpose(Application.Index(sn, , 1)), "~", False), "|")
End Sub
[/VBA]
-
thanks
Thanks Kenneth and snb
Sorry both lost me, kenneth im working on what you gave me thanks
-
Thanks so much I got it, by playing with snb's code a bit.
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules