Hi,
I want a sheet which has 2 multi-select listboxes. Both listboxes have seperate information and I want the user to be able to select more than option from the drop-down.
I found this code online and it works beautifully when I have 1 listbox.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim z
ActiveSheet.Protect Password:="", UserInterfaceOnly:=True
If Target.Column = 12 And Target.Row > 6 Then
' Place the listbox in the selected cell
ActiveSheet.ListBoxes(ActiveSheet.ListBoxes.Count).Cut
ActiveSheet.Paste
With ActiveSheet.ListBoxes(ActiveSheet.ListBoxes.Count)
' Populate the last visited cell
If .Visible Then
For z = 1 To .ListCount
If .Selected(z) And grngCell <> "" Then
Range(grngCell).Value = Range(grngCell).Value & .List(z) & ","
End If
Next
.Visible = False
End If
' Populate the list box with the current values of the cell
For z = 1 To .ListCount
If InStr(1, Target.Value, .List(z), vbTextCompare) Then
.Selected(z) = True
Else
.Selected(z) = False
End If
Next
' Clear the cell value, to accept the new ones
Target.Value = ""
.Visible = True
End With
' Mark the cell for the next update
grngCell = Target.Address
Else
' Make the list invisible and update the cell
With ActiveSheet.ListBoxes(ActiveSheet.ListBoxes.Count)
If .Visible Then
For z = 1 To .ListCount
If .Selected(z) And grngCell <> "" Then
Range(grngCell).Value = Range(grngCell).Value & .List(z) & ","
End If
Next
.Visible = False
End If
End With
End If
How can alter this code so it applies to another listbox in column 10 ?
If I copy this code again replacing column 12 with 10 and variable 'z' with 'x', it doesnt work.
I end up having only 1 listbox in one column, even though I created a second listbox with different drop down values.
Any help would be most appreciated!
Bookmarks