XL: Macro to Delete Link Between List Box and Range of Cells

ID: Q119084


The information in this article applies to:
  • Microsoft Excel for Windows, version 5.0
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel for the Macintosh, version 5.0


SUMMARY

In Microsoft Excel, when you assign values to the List property of the ListBoxes object, the link for that list box is cleared. If you want to remove the link but leave the values that resulted from the link, you can reassign the List property of the list box to the values from the worksheet, and the values will remain even though the link is broken.

This article contains a sample Microsoft Visual Basic for Applications macro that breaks the link between a list box (or a drop-down list box) on a dialog sheet and a worksheet range but leaves the values from that range in the box.


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 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

To Create a Dialog Box With a Linked List Box

  1. In a new workbook, create a dialog sheet, and name it Dialog Example.


  2. In the dialog sheet, create a list box, and name it ListBox.


  3. Select the list box, and on the Format menu, click Object. In the Input Range box, enter the worksheet range that contains the list that you want to appear in the list box.


To Create a Visual Basic Macro to Break the Link but Leave the List

  1. On the Insert menu, click Macro, and then click Module.


  2. On the module sheet, enter the following macro code:
    
          Sub break_link()
             Dialogsheets(1).ListBoxes("ListBox").List = _
             Dialogsheets(1).ListBoxes("ListBox").List
          End sub 
    NOTE: If you are using a drop-down box, substitute the DropDowns object for the ListBoxes object in the code above.


  3. On the Tools menu, click Macro, select the break_link macro, and click Run.


When you select the list box on the dialog sheet and click Object on the Format menu, note that the Input Range box is empty but the list box still contains the values from the worksheet range.

In Microsoft Excel, you can place values in a list box or in a drop-down box by linking the box to a range on a worksheet To do this, select the box, and click Object on the Format menu. Then, enter the desired range in the Input Range box.

Additional query words: 5.00c

Keywords : kbcode kbprg PgmHowto PgmCtrlsStd
Version : MACINTOSH:5.0; WINDOWS:5.0,7.0
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.