VBA : Assign default value to a form control combo box

4.6k views Asked by At

I am trying to display the text Select by default in a form control combo box. I have tried the following but doesn't seem to work. Can someone please suggest what am I doing wrong ?

Option 1:

 Activesheet.shapes("choose_selection").text = "Select your choice"

Option 2:

 Activesheet.shapes("choose_selection").controlformat.text = "Select your choice" 

but I get this error

enter image description here

2

There are 2 answers

1
Minh Bui On

Set the default value in a combo box

The ListIndex property sets the currently selected item using an index number. ListIndex = 1 sets the first value in the array.

Sub ChangeSelectedValue()
  With Worksheets("Sheet1").Shapes("Combo Box 1")
  .List = Array("select your choice","Apples", "Androids", "Windows")
  .ListIndex = 1
 End With
End Sub

Hope it would help.

1
Shai Rado On

Try first defining the DropDown object, and later on display the text in it.

Note: DropDown is the VBA object that refers to Form_Control ComboBox.

Dim drpdown As DropDown

' set the drop-down object
Set drpdown = ActiveSheet.DropDowns("choose_selection")

' modify the drop-down properties
With drpdown
    .Text = "Select your choice"
End With