Sam
Sam

Reputation: 3167

give a combobox in Excel a default selected value with VBA

I have a combobox in Excel created as the picture suggests, and it has a range associated to it.

How can I give it a default value from this range, through VBA?

ActiveSheet.Shapes("DropDown1").ControlFormat.Value = "Germany"

I tried the above code, but it doesn't work. I believe the syntax is not correct. Can you please help? Thank you! enter image description here

Upvotes: 1

Views: 16104

Answers (1)

ddfxraven
ddfxraven

Reputation: 154

You can use the DropDown type, it doesn't show up in the intellisence when you type.

Dim DropDown1 As DropDown
Set DropDown1 = ActiveSheet.DropDowns("DropDown1")

DropDown1.Value = 1

The value is the index of the dropdown, so 1 is the first in the list etc. Use 0 to have no value selected. Also make sure the name "DropDown1" is the correct name for the control, if you right click the control in the excel sheet you'll see the name for the control to the left of the function bar.

Upvotes: 3

Related Questions