The information in this article applies to:
SUMMARY
In Microsoft Excel, you can use the list box control on a dialog sheet to
present a user with a list of items that can be scrolled and selected. You
can use Visual Basic, Applications Edition code to add items to (populate)
this list and to retrieve items from it.
MORE INFORMATIONMicrosoft 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 the Microsoft fee-based consulting line at (800) 936-5200. 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/overview/overview.asp SAMPLE VISUAL BASIC CODE TO ADD ITEMS TO A LISTTo populate a list box with data from cells on a worksheet
NOTE: "MyWorksheet" is the name of the worksheet that contains the data you
would like placed in the list box.
To populate a list box using an array
To populate the list box with data from a horizontal array of cellsOrdinarily, list boxes are populated with a column of data. If you need to populate a list box with a row of data, use this code:
NOTE: "Sheet1" is the worksheet that contains your data.
SAMPLE VISUAL BASIC CODE TO REMOVE ITEMS FROM A LISTTo clear all items in a list box with RemoveAllItems
For additional information, please see the following article in the
Microsoft Knowledge Base:
Q105877 XL: RemoveItem and RemoveAllItems Methods May Not Work SAMPLE VISUAL BASIC CODE TO RETRIEVE ITEMS FROM A LISTTo retrieve the selected item in a single-select list box
For additional information, please see the following article in the
Microsoft Knowledge Base:
Q124214 XL: Returning a Value from a List Box in Visual Basic To retrieve the selected items from a multi-select list box
For additional information, please see the following article in the
Microsoft Knowledge Base:
Q111564 XL: Determining Which Items Are Selected in a List Box To retrieve all items in a list box using a For-Each statement
REFERENCES"Visual Basic User's Guide," pages 226, 231 Additional query words: 5.00a 5.00c Dialogs ListBox XL98 XL97 XL7 XL5
Keywords : kbcode kbprg PgmHowto PgmCtrlsStd |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |