XL: Macro to Insert Data from a List Box into the Active CellLast reviewed: February 3, 1998Article ID: Q140034 |
The information in this article applies to:
SUMMARYThis article contains a sample Microsoft Visual Basic for Applications macro (Sub procedure) that enters a selected item from a list box into the active cell on a worksheet.
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 engineers 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/refguide/default.aspBefore you create the sample macro, follow these steps:
Sample Visual Basic Procedure
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 SubTo assign the macro to the list box control, follow these steps:
REFERENCESMicrosoft Press: "Microsoft Excel 5 Visual Basic for Applications Reference," 599-600
|
Additional query words: 5.00 5.00c 5.00a 7.00 8.00 XL98 XL97 XL7 XL5
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |