Microsoft KB Archive/109575

From BetaArchive Wiki

Article ID: 109575

Article Last Modified on 10/11/2006



APPLIES TO

  • Microsoft Excel 97 Standard Edition
  • Microsoft Excel 98 for Macintosh



This article was previously published under Q109575


SYMPTOMS

In Microsoft Visual Basic for Applications, you cannot add a new series to a chart in Microsoft Excel using an array as the Source argument with the Add method of the SeriesCollection object. If you specify the new data as an array of data points, you receive the following error message and your data points are not added to the chart:

Run-time error '1004':
Reference is not valid.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to 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 requirements. To add a new series to a chart in Microsoft Excel using the SeriesCollection object, use either of the following methods.

Method 1: Create a New Series From an Array

Although you cannot create a new series from an array in one statement, it is possible to use two steps to complete the task. The following is an example of using this two-step method:

   Sub Series()
       'Dimension variable x as Integer data type
       Dim x as Integer
       Sheets("Sheet1").Select
       ActiveSheet.ChartObjects(1).Select
       Selection.Chart.SeriesCollection.Add Source:=Range("A1")
       x = Selection.Chart.SeriesCollection.Count
       Selection.Chart.SeriesCollection(x).Values = Array(5, 6, 7)
   End Sub
                

Method 2: Use the Add Method

To add a new series to a chart in Microsoft Excel using the Add method of the SeriesCollection object, use a Range as the Source argument. For example, to add the range C1:C4 on Sheet1 as a new series to the active chart, use the following syntax:

   ActiveChart.SeriesCollection.Add _
 
       Source:=Sheets("Sheet1").Range("C1:C4")
                

MORE INFORMATION

The information in the Visual Basic Reference in Help incorrectly states that the source argument of the Add method (SeriesCollection) specifies the new data and can be either a Range or an array of data points. However, specifying an array of data points as a series with the Add method will produce the error stated above.

REFERENCES

For more information about the Add Method (SeriesCollection), click the Search button in Help and type:

Add Method


For more information about the Array Function, click the Search button in Help and type:

array



Additional query words: 5.00a 5.00c 8.00 XL98 XL97 XL7 XL5 Run-time error 1004 Reference is not valid XL

Keywords: kbdtacode kberrmsg kbprb kbprogramming KB109575