May 06 2022 10:59 AM
Hi Everyone,
I have a problem that I have tried every solution I can think of to solve.
I have a Listbox that contains multiple contract codes (A029, A031, A032, etc...) that is set to multi-select. I need the selected values from the listbox to concatenate into a specific cell (C7 on the Output tab) seperated by /'s. I then need to clear the selections from the list box and the value of C7 when the CLEAR FORM button is selected.
Example:
If the User selects A029, A032, and A080 the value in C7 would read A029/A032/A080, or
If the User selects A063 and A114 the value in C7 would read A063/A114
Any thoughts on how to accomplish this?
May 06 2022 11:21 AM
Create a macro in a standard module (the kind you create by selecting Insert > Module in the Visual Basic Editor):
Sub ListValues()
Dim lbx As ListBox
Dim i As Long
Dim s As String
Set lbx = Worksheets("ListBox").ListBoxes(Application.Caller)
For i = 1 To lbx.ListCount
If lbx.Selected(i) Then
s = s & ", " & lbx.List(i)
End If
Next i
If s <> "" Then
s = Mid(s, 3)
End If
Worksheets("Output").Range("C7").Value = s
End Sub
Assign this macro to the list box.
May 06 2022 11:34 AM
May 06 2022 12:09 PM