Computing.Net > Forums > Programming > VBA combo boxes

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBA combo boxes

Reply to Message Icon

Name: gpp
Date: December 23, 2003 at 10:37:54 Pacific
OS: MS Server2003
CPU/Ram: 1g, 512m
Comment:

Need help with VBA and excel. I'm trying to write a macro for excel, with multiple combo boxes. When populating these boxes, I would like to store the primary key alongside the name. With regular VB, this can be done using the .ItemData method. This method doesnt seem to exist in VBA. Does anyone have any idea how this can be done.

Thanks,
greg



Sponsored Link
Ads by Google

Response Number 1
Name: egkenny
Date: December 24, 2003 at 20:13:42 Pacific
Reply:

In VBA you can make use of multiple columns to make up for this.
For example the following Combo Control has two columns for each row.

ComboBox1.Clear ' Clear list box
ComboBox1.ColumnCount = 1 ' Display only first item in list box
ComboBox1.AddItem "" ' Create 1st row entry
ComboBox1.List(0, 0) = "Thunderbird" ' Set Row 1, Col 1: data
ComboBox1.List(0, 1) = 101 ' Set Row 1, Col 2: key
ComboBox1.AddItem "" ' Create 2nd row entry
ComboBox1.List(1, 0) = "Bluejay" ' Set Row 2, Col 1: data
ComboBox1.List(1, 1) = 102 ' Set Row 2, Col 2: key

Debug.Print ComboBox1.List(0) ' Print Row 1, Col 1
Debug.Print ComboBox1.List(0, 0) ' Print Row 1, Col 1
Debug.Print ComboBox1.List(0, 1) ' Print Row 1, Col 2

Debug.Print ComboBox1.List(1) ' Print Row 2, Col 1
Debug.Print ComboBox1.List(1, 0) ' Print Row 2, Col 1
Debug.Print ComboBox1.List(1, 1) ' Print Row 2, Col 2

Debug.Print Val(ComboBox1.List(0, 1)) ' Print Key for Row 1
Debug.Print Val(ComboBox1.List(1, 1)) ' Print Key for Row 2


0
Reply to Message Icon

Related Posts

See More


Tell me how to edit this ... determine VB app install ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBA combo boxes

MS-Access VBA Combo box www.computing.net/answers/programming/msaccess-vba-combo-box/5587.html

Combo Boxes in VBA www.computing.net/answers/programming/combo-boxes-in-vba/9015.html

Populating a combo box vba www.computing.net/answers/programming/populating-a-combo-box-vba/15098.html