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?
 

Some videos you may like

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)

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
75,804
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
75,804
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
 

Watch MrExcel Video

Forum statistics

Threads
1,108,509
Messages
5,523,312
Members
409,511
Latest member
hitesh222002

This Week's Hot Topics

Top