XL: Visual Basic Macro to Break Chart Links

Last reviewed: February 2, 1998
Article ID: Q124232
The information in this article applies to:
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel 98 Macintosh Edition

SUMMARY

Although charts in Microsoft Excel are, by default, linked to the range of cells on the worksheets that they were created from, these links can be broken by converting the cell references in the SERIES formula for the chart to values. This article contains a sample Visual Basic for Applications macro that you can use to do this.

MORE INFORMATION

The following macro can be run for any active chart. For the purpose of this macro, a chart is active when any of the following are true:

  • A Microsoft Excel chart sheet is active.

        -or-
    
  • A chart embedded on a worksheet is selected by clicking it.

        -or-
    
  • A chart embedded on a worksheet is activated by double-clicking (versions 5.0 and 7.0).

Visual Basic Code Example

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 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/supportnet/refguide/ 


   Sub BreakChartLinks()

   For Each x In ActiveChart.SeriesCollection
      x.Values = x.Values
      x.XValues = x.XValues
      x.Name = x.Name
   Next x

   End Sub

REFERENCES

"Microsoft Excel User's Guide," version 5.0, Chapter 15, page 269, "Activating an Embedded Chart"

For more information about the Values property, click the Search button in Visual Basic Programming Help and type:

   Values

For information about a way method to accomplish this same task manually, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q62377
   TITLE     : Excel: Breaking Link Between Chart and Worksheet

For information about a method to accomplish this same task using the Microsoft Excel 4.0 macro language, see the following article

   ARTICLE-ID: Q78463
   TITLE     : Excel: Removing Chart Links to a Worksheet in a Macro


Additional query words: 5.00 5.00a 5.00c 7.00 7.00a 97 break link
Keywords : xlchart xlvbahowto kbcode kbprg
Version : WINDOWS:5.00,5.0c,7.0,7.0a,97; MACINTOSH:5.0,98
Platform : MACINTOSH WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.