XL: "Invalid External Reference" Using ChartWizard Method

Last reviewed: February 2, 1998
Article ID: Q126817
5.00 5.00c 7.00 | 5.00 5.00a
WINDOWS         | MACINTOSH
kbprg kbcode

The information in this article applies to:

  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0

SYMPTOMS

In Microsoft Excel, you may receive the following error message when you run a Visual Basic, Applications Edition, procedure that contains the ChartWizard method:

   Run-time error '1004':

   External reference is not valid

CAUSE

This problem occurs if the Source argument that you use with the ChartWizard method contains a number of nonadjacent range references. Note that the number of the range references that will cause this error message depends on the length of the name of the worksheet that the chart is created on.

For example, the following procedure correctly creates a chart on the active sheet, Sheet1, (assuming that the range A1:B14 on Sheet1 contains data):

   Sub CreateChart()
      ActiveSheet.ChartObjects.Add(100, 40, 300, 200).Select
      Application.CutCopyMode = False
      ActiveChart.ChartWizard Source:= Range( _
        "A1:B1,A2:B2,A3:B3,A4:B4,A5:B5,A6:B6,A7:B7," _
        & "A8:B8,A9:B9,A10:B10,A11:B11,A12:B12,A13:B13")
   End Sub

If you add another reference in the Range object for the Source argument, you receive the error message described above when you run the procedure.

This problem occurs because Visual Basic converts the range string ("A1:C1,A2:C2,...") into a parsed reference. When you use the ChartWizard method with this reference, the ChartWizard method converts this reference to a string. When this occurs, the reference is converted to R1C1 format, and the sheet name is added to each individual reference. This causes the reference string to exceed the allotted buffer, and to be cut off. Because the reference is cut off, you receive the error message above when the ChartWizard method attempts to create the chart.

Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

RESOLUTION

To avoid receiving the error message above, use one of the following methods.

Method 1: Use the MS Excel 4.0 Macro equivalent, CHART.WIZARD().

          The CHART.WIZARD() function works correctly with nonadjacent cell
          references because the range remains a string and does not need
          to be converted. The original string that you use as the Ref
          argument in the CHART.WIZARD function is the string that is
          parsed.

Method 2: Copy and paste the cells in the range from which you are creating
          the chart so that they appear as one contiguous range. This range
          can then be referred to as one single range in the ChartWizard
          method.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft Excel versions listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The ChartWizard method modifies the properties of the given chart and allows a chart to be quickly formatted without setting all the individual properties. This method is non-interactive and changes only the specified properties.

One of the named arguments for the ChartWizard method is called Source. The Source argument is used to specify the range that contains the source data for the chart. It is required if you are creating a chart and is optional if you are editing an existing chart.

If Source is omitted and the selection is not an embedded chart on the active worksheet, or the active sheet is not an existing chart, the method fails and an error occurs.

REFERENCES

For more information about the ChartWizard Method, choose the Search button in Help and type:

   ChartWizard Method


KBCategory: kbprg kbcode
KBSubcategory:

Additional reference words: 7.00 5.00 5.00c
Keywords : kbcode
Version : WINDOWS:5.0,5.0c,7.0; MACINTOSH:5.0,5.0a


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.