How to Add Data to a ComboBox or a ListBoxID: Q161598
|
This article describes methods of populating a ComboBox or ListBox control.
Microsoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/refguide/You can use a control, such as a combo box or a list box, on a user form. In Microsoft Excel, you can use these controls in the worksheet. The methods for populating the controls are similar. The examples in this article use controls on a user form.
A1: One B1: Red
A2: Two B2: Green
A3: Three B3: Yellow
A4: Four B4: Blue
myarray1 = Array("One", "Two", "Three", "Four")
myarray2 = Array("Red", "Green", "Yellow", "Blue")
For x = 0 to 3
ListBox1.AddItem myarray1(x)
Next x
For y = 0 to 3
ComboBox1.AddItem myarray2(y)
Next y
This code should appear between the lines "Sub UserForm_Initialize()"
and "End Sub".
For more information about user forms, click the Index tab in Microsoft Visual Basic Help, type the following text:
UserForm Objectand then double-click the selected text to go to the "UserForm Object" topic.
Additional query words: XL97 97 userform user form combo box list vba
Keywords : kbprg kbdta kbdtacode OffVBA KbVBA
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 2, 1999