Hello,
I have a Userform set up with two list boxes and 1 command button.
The first List box will display a list of Sectors in which you can choose multiple entries. The second list box will display Subsectors and the command button should take whatever have been chosen to the desired cells. I would like the selection from the first list box to be taken to cells in the column "Sectors" and the selection from the second list box to go to the cells in the column named "subsectors".
So far my code works however I would like to be able to input different entries for each row. At the moment the code I have written changes the entire column.
Can anyone help? Please see code below
[TABLE="width: 500"]
<tbody>[TR]
[TD]Private Sub UserForm_Initialize()
With ListBox1
.List = Range("Cover!B3:B8").Value 'Range of cells with the list of sectors
.MultiSelect = fmMultiSelectMulti
End With
With ListBox2
.List = Range("Cover!C3:C8").Value 'Range of cells with list of sub-sectors
.MultiSelect = fmMultiSelectMulti
End With
UserForm1.Caption = "Select Sectors"
CommandButton1.Caption = "Select"
End Sub
Private Sub CommandButton1_Click()
Sectors = ""
For x = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(x) Then
If Sectors = "" Then
Sectors = Me.ListBox1.List(x, 0)
Else
Sectors = Sectors & "," & Me.ListBox1.List(x, 0)
End If
End If
Next x
ThisWorkbook.Sheets("Europe_Sector_Overview").Range("Sector") = Sectors
Subsectors = ""
For x = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox2.Selected(x) Then
If Subsectors = "" Then
Subsectors = Me.ListBox2.List(x, 0)
Else
Subsectors = Subsectors & "," & Me.ListBox1.List(x, 0)
End If
End If
Next x
ThisWorkbook.Sheets("Europe_Sector_Overview").Range("Sub_Sector") = Subsectors
Me.Hide
End Sub
[/TD]
[/TR]
</tbody>[/TABLE]
I have a Userform set up with two list boxes and 1 command button.
The first List box will display a list of Sectors in which you can choose multiple entries. The second list box will display Subsectors and the command button should take whatever have been chosen to the desired cells. I would like the selection from the first list box to be taken to cells in the column "Sectors" and the selection from the second list box to go to the cells in the column named "subsectors".
So far my code works however I would like to be able to input different entries for each row. At the moment the code I have written changes the entire column.
Can anyone help? Please see code below
[TABLE="width: 500"]
<tbody>[TR]
[TD]Private Sub UserForm_Initialize()
With ListBox1
.List = Range("Cover!B3:B8").Value 'Range of cells with the list of sectors
.MultiSelect = fmMultiSelectMulti
End With
With ListBox2
.List = Range("Cover!C3:C8").Value 'Range of cells with list of sub-sectors
.MultiSelect = fmMultiSelectMulti
End With
UserForm1.Caption = "Select Sectors"
CommandButton1.Caption = "Select"
End Sub
Private Sub CommandButton1_Click()
Sectors = ""
For x = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(x) Then
If Sectors = "" Then
Sectors = Me.ListBox1.List(x, 0)
Else
Sectors = Sectors & "," & Me.ListBox1.List(x, 0)
End If
End If
Next x
ThisWorkbook.Sheets("Europe_Sector_Overview").Range("Sector") = Sectors
Subsectors = ""
For x = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox2.Selected(x) Then
If Subsectors = "" Then
Subsectors = Me.ListBox2.List(x, 0)
Else
Subsectors = Subsectors & "," & Me.ListBox1.List(x, 0)
End If
End If
Next x
ThisWorkbook.Sheets("Europe_Sector_Overview").Range("Sub_Sector") = Subsectors
Me.Hide
End Sub
[/TD]
[/TR]
</tbody>[/TABLE]