Microsoft KB Archive/213748

= XL2000: How to Populate One List Box Based on Another List Box =

Article ID: 213748

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213748





SUMMARY
This article contains an example of using the selected item in one list box control on a UserForm to determine the list that will populate a second list box control.



MORE INFORMATION
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 Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

 Close and save any open workbooks, and then open a new workbook.  On Sheet1, enter the following values:   A1: North Carolina  B1: Charlotte   C1: Charleston  D1: Charlottesville A2: South Carolina B2: Greensboro  C2: Columbia    D2: Norfolk A3: Virginia       B3: Raleigh     C3: Greenville  D3: Richmond  Start the Visual Basic Editor (press ALT+F11). If the Properties window is not visible, click Properties Window on the View menu (or press F4). On the Insert menu, click UserForm. Draw a list box control on the UserForm.</li> Open the Properties window (press F4).</li> Select the RowSource property and type Sheet1!A1:A3 .</li> Draw another list box control on the UserForm.</li> Double-click the ListBox1 control (from Step 6) to open the Code window for the UserForm.</li>  In the module, type the following code for the ListBox1 Click event: Private Sub ListBox1_Click

'Get the currently selected item Select Case ListBox1.Value

'If North Carolina, set RowSource property of ListBox2 'to Column B.  Case "North Carolina" ListBox2.RowSource = "Sheet1!B1:B3" 'If South Carolina, set RowSource property of ListBox2 'to Column C.  Case "South Carolina" ListBox2.RowSource = "Sheet1!C1:C3"

'If Virginia, set RowSource property of ListBox2 to  'Column D.   Case "Virginia" ListBox2.RowSource = "Sheet1!D1:D3"

End Select

End Sub </li> Run the UserForm.

When you click one of the items in ListBox1, the list in ListBox2 is updated, reflecting the choice that you made in ListBox1.</li> Close the UserForm.</li></ol>

<div class="references_section">