Microsoft Excel - How to select ActiveX combobox value using vba

Asked By Anderson Ahrenhold on 04-Dec-15 03:18 PM
I have 12 activex comboboxes in a worksheet. All 12 of these comboboxes have 2 selections either "ON" or "OFF".

I have a named range on a different worksheet, let's call it "Selector" which is a drop down list with numbers 1 through 12.

I would like to be able to use VBA to turn on what ever project is selected in the selector and turn off the remaining comboboxes. What I have now is this:

If Range("Selector").Value = 1 Then
                                          ComboBox1 = "ON"
                                              ComboBox13 = "OFF"
                                              ComboBox14 = "OFF"
                                              ComboBox15 = "OFF"
                                              ComboBox16 = "OFF"
                                              ComboBox17 = "OFF"
                                              ComboBox18 = "OFF"
                                              ComboBox19 = "OFF"
                                              ComboBox20 = "OFF"
                                              ComboBox21 = "OFF"
                                              ComboBox22 = "OFF"
                                              ComboBox23 = "OFF"

The comboboxes are out of order so assume combobox13 = 2, combobox14 = 3, etc...

The error I am having is referencing the combobox itself.

Thanks for any and all help.

Harry Boughen replied to Anderson Ahrenhold on 04-Dec-15 10:44 PM
Hello Anderson,

I assume that you want to value displayed by the ComboBox to match the value in the linked cell.  If so, your logic should be changing the value of the linked cell for the appropriate ComboBox.  If the linked cell is set to ON, then the ComboBox will show ON and vice versa.  Fairly obviously you would need to also have some logic to set all of the linked cells to OFF and I would be thinking of using the CASE statement to make the changes after that.

Also, if I can just say that I am not at all clear why you are using a ComboBox if you are not using it to actually make a selection.

If you need more help just sing out.

Harry