Vba combobox interfacing in Excel
A combo box controls has the functionality of both text box and a list box.
This control is most often used in many applications.
Combo box allows the user to select an item either by typing it or by choosing from the list.
This control s most efficient, when a selection of text without any spell mismatch is required in the application.
The control presents a list of choices to the user.
If the list exceeds the size of the control, a scrollbar will automatically be added.
Properties of Combobox
1.Value
This property is used to either get or set the value of the combobox control.
It is nothing but the curently selected item in the control.
2.Style
This property is used to specify how the control should look like.
There are three values
1.vbComboDropdown
2.vbComboSimple
3.vbComboList
3.Items
This property is used to get the list of items I the combobox.
The Add() method associated with this property is used to add new items to the control.
4.Index
This property specifies the index of the items in the combobox.
The index starts with 0 and -1 specifies an empty list.
5.Font Property
This property is used to set the font of the items in the list.
Events associated with Combobox:
The important and often used event associated with the combobox is "Change" event.
This event is triggered whenever a selection is made in the combobox.
The following example illustrates this.
- Private Sub ComboBox1_Change()
- MsgBox ComboBox1.Value
- End Sub