VBA Code to Create a Combo Box in Excel

VBA Code:

' VBA Code to Create a Combo Box in Excel

Sub CreateComboBox()
    Dim ws As Worksheet
    Dim comboBox As OLEObject
    Dim comboBoxTop As Double
    Dim comboBoxLeft As Double
    Dim comboBoxWidth As Double
    Dim comboBoxHeight As Double
    
    ' Set the worksheet to work with
    Set ws = ThisWorkbook.Worksheets("Sheet1") ' Replace with the name of your worksheet
    
    ' Set the dimensions and position of the combo box
    comboBoxTop = 100 ' Replace with the desired top position
    comboBoxLeft = 100 ' Replace with the desired left position
    comboBoxWidth = 120 ' Replace with the desired width
    comboBoxHeight = 20 ' Replace with the desired height
    
    ' Create the combo box
    Set comboBox = ws.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
        DisplayAsIcon:=False, Left:=comboBoxLeft, Top:=comboBoxTop, _
        Width:=comboBoxWidth, Height:=comboBoxHeight)
    
    ' Customize the combo box properties
    With comboBox
        .Name = "ComboBox1" ' Replace with the desired name for the combo box
        .Object.AddItem "Option 1" ' Add items to the combo box
        .Object.AddItem "Option 2"
        ' Add more items as needed
        
        ' Customize other combo box properties as needed
        
        ' Add event handler code for combo box events, if necessary
        ' For example, to execute a specific procedure when the selection changes:
        '.Object.OnChange = "ComboBox1_Change"
    End With
    
    ' Display a message
    MsgBox "Combo box has been created."
End Sub


Check All VBA Codes

Join Our Telegram Group

Join the TechGuruPlus Telegram group

Join Our WhatsApp Group

Join the TechGuruPlus WhatsApp group
Nazim Khan, founder of TechGuruPlus.com

— Founder & Editor, TechGuruPlus.com
[MBA in Finance]

Nazim Khan has spent over ten years working with Excel, Tally and office documentation in accounts, finance and MIS roles. He has been running TechGuruPlus.com since 2016, where he publishes free editable templates for office work, and the YouTube channel Business Excel. He has trained more than 50,000 people online. Every template on this site is built and checked by him before it is published.

Contact  Â·  Excel Course

Leave a Comment