How to set ComboBox default value?

bmacd615

New Member
Joined
Mar 28, 2009
Messages
8
I want the combobox cmbBottle to show the second item in its list when the userform shows. The code below achieves this. However, after executing cmbbottle.listindex=1, the program jumps out of the initialization and goes to Private Sub cmbBottle_change() and then executes others subs called under it. I don't want this.
Is there a way to set the combobox to a default, startup display, without triggering the cmbBottle_change event?
(I have looked under the Properties window of combobox in the form view mode and can't see how to set it's value there.)

Private Sub UserForm_Initialize()
cmbBottle.ListIndex = 1
.
.
.
.

Private Sub cmbBottle_change()
SelectCaseBottle
.
.
.
 
Thanks for sharing that, Mike.

Great trick!

Is nice to count with someone with your knowledge.

:biggrin:
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I was also stuck on the same problem to set default value in a combo box and after reading this thread I figured out how simple it is. Thanks to regular bosses who solve our problems in this forum regularly and easily :)
 
Upvote 0
Great!! That´s it.

Thank you very much, Scott.

Though it didn´t work if I use RowSource, so I had to use .additem to fill the list in the combobox. But It works perfect.

This is how it goes in case anybody finds it helpful:

Code:
Private Sub UserForm_Initialize()
Dim cboItem As Range
For Each cboItem In Worksheets(1).Range("nameoftherange")
  With Me.combobox1
    .AddItem cboItem.Value
End With
Next cboItem
[COLOR=Blue]Me.combobox1.Text = Me.combobox1.List(Me.combobox1.ListCount - 1)[/COLOR]
End Sub

I had the same problem and have found that the reason why it did not work with RowSource was because I was also using control source, so if this was the case here also then this will work:

Code:
Private Sub UserForm_Initialize()

me.combobox1.RowSource = "RowSource"

[COLOR=Blue]wsSheetWithControlSource.Range(me.combobox1.controlsource).value = Me.combobox1.List(Me.combobox1.ListCount - 1)
[/COLOR]
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,858
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top