Combobox default

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
361
I've got five items in my combobox. How do I get it to display the fifth item on initialisation?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Tuelor

Board Regular
Joined
Mar 19, 2011
Messages
101
I presume you are using the form control combo box?

You could do it using the Active ComboBox, and after adding your list, set the combo box value to your 5th item.

D
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows
Something like this in the form's Initialize event.
Code:
ComboboBox1.ListIndex = ComboBox1.ListCount-1
 

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
361

ADVERTISEMENT

Almost
There are 5 items in the combobox - each is a month loaded from a named range. I want the combobox to select the last entry as a default.

I suspect seltext is the way to go but can't get it to sel the last item. Something like
combobox5.seltext combobox5.listcount+1.text

ziggy
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows
What do you mean by 'select'?

The code I posted will definitely set the value in the combobox to the last item in the list.

If you want to have it highlighted/selected try this, though I'm not sure why you would want to.:)
Code:
    ComboBox1.ListIndex = ComboBox1.ListCount - 1
    ComboBox1.SelStart = 0
    ComboBox1.SelLength = Len(ComboBox1.Value)
 

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
361
Your first post did work. I didn't change the second instance of combobox1 to 5 in my code.
The text gets selected as well.
thanks for your help.

cheers
ziggy
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,598
Messages
5,832,644
Members
430,150
Latest member
amitk1

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
Top