Log in

View Full Version : Remove Item in Dropdown Box if Selected in Another Dropdown Box



hunter21188
04-28-2017, 09:23 AM
I have a userform in Powerpoint that has 5 pages on it (tabs across the top, each one you click takes you to a new page within the same userform). I have one combobox dropdown on each page. They are all populated from the same location (a module in the vba code). Here is the code where the list of dropdown options are stored:


Sub HazardTypeSevere()


'List of items to include in the Severe dropdown.


Dim strlist As String
'Put them in an Array declared as Public
strlist = "Damaging Winds,Tornadoes,Hazardous Travel"
rayNames = Split(strlist, ",")


End Sub


In my userform code, this is the code that populates the dropdown:


Private Sub HazardType2_DropButtonClick()
Call DropdownOptions.HazardTypeSevere


'List all the severe hazard type dropdown options in Hazard 2


If HazardType1 <> "" Then 'If anything is selected in hazardtype1 dropdown
HazardType2.RemoveItem (HazardType1.Value) "Then remove the selected value from the HazardType2 dropdown.
'End If


Dim L As Long


If HazardType2.ListCount = 0 Then
With HazardType2
.Clear
For L = 0 To UBound(rayNames)
.AddItem rayNames(L)
Next L
.Value = rayNames(0)
End With
End If
End If


End Sub

When I run the code above I get the "Invalid Argument" error. The 'HazardType1.Value' does indeed show what is selected in the HazardType1 dropdown.

I'm not sure if this is possible without having a separate list of items written to call on to populate the dropdown. But that would not be possible since there are a lot of options in the dropdown boxes.
Thanks for taking a look at this!