What I would like to accomplish is the following...
I have a ListBox object that has 5 options within it to multiselect. In certain cases if an option is selected a certain other option would then disappear from the ListBox, for example if Option 2 is chosen then Option 5 would not be applicable so I would remove it from the list, if Option 2 is unchecked I would then like Option 5 to re-appear within the ListBox. I assume I would be doing this using the .AddItem and .RemoveItem tags in VBA, however I am not sure that the other portion of my code would work out if I do remove and/or add certain options within the ListBox. That portion of code is the following, I want to be able to determine which options are selected within the ListBox via VBA, if Option 2 is the second option and that returns a ( 2 ) in the .Selected tag in VBA and then I were to REMOVE Option 5, if Option 6 was then selected I assume that's now going to return ( 5 ) as .Selected since its the 5th option in the ListBox. If this becomes too complicated I may just do with with CommandButtons and changing visibilities of certian buttons based on the selection of others.
I have the following VBA written which I thought would help me to determine which checkbox(es) are selected within a ListBox object, but I don't seem to be getting the results that I want when using this on a sheet.
Private Sub ListBox1_Click()
Dim x As Integer
With ListBox1
For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
Debug.Print .List(x)
End If
Next x
End With
End Sub
I have a ListBox object that has 5 options within it to multiselect. In certain cases if an option is selected a certain other option would then disappear from the ListBox, for example if Option 2 is chosen then Option 5 would not be applicable so I would remove it from the list, if Option 2 is unchecked I would then like Option 5 to re-appear within the ListBox. I assume I would be doing this using the .AddItem and .RemoveItem tags in VBA, however I am not sure that the other portion of my code would work out if I do remove and/or add certain options within the ListBox. That portion of code is the following, I want to be able to determine which options are selected within the ListBox via VBA, if Option 2 is the second option and that returns a ( 2 ) in the .Selected tag in VBA and then I were to REMOVE Option 5, if Option 6 was then selected I assume that's now going to return ( 5 ) as .Selected since its the 5th option in the ListBox. If this becomes too complicated I may just do with with CommandButtons and changing visibilities of certian buttons based on the selection of others.
I have the following VBA written which I thought would help me to determine which checkbox(es) are selected within a ListBox object, but I don't seem to be getting the results that I want when using this on a sheet.
Private Sub ListBox1_Click()
Dim x As Integer
With ListBox1
For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
Debug.Print .List(x)
End If
Next x
End With
End Sub