yellowtiger
New Member
- Joined
- Mar 26, 2021
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
I have a list box on my VBA form with a list of U.S. States. The person filling out the form will select states they wish to be licensed in for work. Following their selection and submitting the form I want the states they have selected to appear in 5 predetermined categories with a "," between them. I have figured out how to do this for the whole list in one cell with the code below, however I am having difficultly getting certain states they select to appear in different cells. I would greatly appreciate any help, thank you
myVar = ""
For x = 0 To Me.ListBox.ListCount - 1
If Me.ListBox.Selected(x) Then
If myVar = "" Then
myVar = Me.ListBox.List(x, 0)
Else
myVar = myVar & "," & Me.ListBox.List(x, 0)
End If
End If
Next x
ThisWorkbook.Sheets("Data").Range("H17") = myVar
myVar = ""
For x = 0 To Me.ListBox.ListCount - 1
If Me.ListBox.Selected(x) Then
If myVar = "" Then
myVar = Me.ListBox.List(x, 0)
Else
myVar = myVar & "," & Me.ListBox.List(x, 0)
End If
End If
Next x
ThisWorkbook.Sheets("Data").Range("H17") = myVar