XL2000: How to Programmatically Insert Data from a List Box into the Active Cell

Article translations Article translations
Article ID: 213363 - View products that this article applies to.
This article was previously published under Q213363
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all


This article describes a sample Microsoft Visual Basic for Applications Sub procedure (macro) that enters a selected item from a list box into the active cell on a worksheet.

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 Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

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 To create and use a sample macro to enter a selected item from a list box into the active cell on a worksheet, use the steps in the following example:
  1. Start Excel and open a new worksheet.
  2. Enter the following data in the worksheet:
    A1: One
    A2: Two
    A3: Three
  3. On the View menu, point to Toolbars, and then click to select the Forms checkbox (if not already checked).
  4. On the Forms toolbar, click List Box.
  5. Draw a list box on the worksheet.
  6. Right-click the list box to select it (if it is not already selected).
  7. On the Format menu, click Control.
  8. Click the Control tab.
  9. In the Input range box, type A1:A3, and then click OK.
  10. Press ALT+F11 to start the Visual Basic editor.
  11. On the Insert menu, click Module.
  12. In the module sheet, type the following code:
    Sub Test()
        Dim Lbox As Object
        ' Create the Lbox object, which will be the list box on the Active
        ' sheet.
        ' Activesheet can be changed to sheets("test") where test is the
        ' name of the sheet on which you want the information.
        Set Lbox = ActiveSheet.ListBoxes(1)
        ' Check to see the value (or what is selected) of the list box. If
        ' zero, exit the Sub.
        If Lbox.Value = 0 Then Exit Sub
        ' Change the value of the Active cell to be what is selected in the
        ' list box
        ActiveCell.Value = Lbox.List(Lbox.Value)
        ' Set the list box back to zero or nothing selected.
        Lbox.Value = 0
    End Sub
  13. Right-click the list box control.
  14. On the shortcut menu, click Assign Macro.
  15. In the Macro name list, click Test, and then click OK.
  16. Select Cell A4 (or any blank cell).
  17. On the Tools menu, point to Macro, and then click Macros.
  18. In the Macro name list, click Test, and then click Run.
  19. In the list box, click Two. Cell A4 returns Two.
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.


Article ID: 213363 - Last Review: October 25, 2013 - Revision: 1.0
Applies to
  • Microsoft Excel 2000 Standard Edition
kbnosurvey kbarchive kbdtacode kbhowto kbprogramming KB213363

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com