Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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: keyDebug.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 2Debug.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 2Debug.Print Val(ComboBox1.List(0, 1)) ' Print Key for Row 1
Debug.Print Val(ComboBox1.List(1, 1)) ' Print Key for Row 2

![]() |
Tell me how to edit this ...
|
determine VB app install ...
|

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