Search code examples
excelvbacombobox

ActiveX Combo boxes self generating by the 100s


Excel is stacking 100s of combo boxes in the same spot on one of my sheets.

I have coding in place with the combo boxes, but it is only to adjust the size of the font.

I also have tried to delete the boxes manually but when I cleaned up 254 of them I switched tabs. did some work, saved and came back to sheet one and there were 504 combo boxes.

Here is the macro for the combo boxes. I am using the ActiveX version.

Private Sub ComboBox3_Change()
    Dim cb As ComboBox

    With ActiveSheet

        Set cb = .OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
                                 DisplayAsIcon:=False, Left:=322.5, Top:=11.5, Width:=176.5, Height:= _
                                 61.5).Object

        cb.Font.Size = 20

    End With

End Sub

Solution

  • That code , add a Combobox in the same place everytime that a event called

    Change

    is triggered , So everytime u change the value of the Combo , another one is placed in front of that.

    To stop that , stop adding , instead

    set cb = .oleobjects.add()
    

    use

       set cb = .olebjects("HEREPUTYOURCHECKNAME")
    

    .

    Set cb = .OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
                             DisplayAsIcon:=False, Left:=322.5, Top:=11.5, Width:=176.5, Height:= _