Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Creating Charts in VBA.

Creating Charts in VBA

Written by Allen Wyatt (last updated September 21, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


Excel is very handy at creating charts from data in a worksheet. What if you want to create a chart directly from VBA, without using any data in a worksheet? You can do this by "fooling" Excel into thinking it is working with information from a worksheet, and then providing your own. The following macro illustrates this concept:

Sub MakeChart()
    'Add a new chart
    Charts.Add

    'Set the dummy data range for the chart
    ActiveChart.SetSourceData Sheets("Sheet1").Range("a1:d4"), _
      PlotBy:=xlColumns

    'Manually set the values for the data series
    ActiveChart.SeriesCollection(1).Formula = _
      "=SERIES(""First Data"",{""a"",""b"",""c"",""d""},{2,3,4,5},1)"
    ActiveChart.SeriesCollection(2).Formula = _
      "=SERIES(""Second Data"",{""a"",""b"",""c"",""d""},{6,7,8,9},2)"
    ActiveChart.SeriesCollection(3).Formula = _
      "=SERIES(""Third Data"",{""a"",""b"",""c"",""d""},{10,11,12,13},3)"
End Sub

The comments in this example explain what is going on for each step. When setting the dummy data range, the SetSourceData method assumes the range is on a worksheet named Sheet1. If you don't have such a sheet in your workbook, you need to alter the command accordingly.

Later, when manually setting the values for the data series, the SERIES command is used to specify the label for the series (First Data, Second Data, and Third Data), the array of category labels (a, b, c, and d in all series), the array of values for the series, and a number specifying which series number this represents.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2622) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Creating Charts in VBA.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Anchoring Comment Boxes in Desired Locations

Want your comment boxes to appear someplace other than the right side of a cell? You may be out of luck, and here's why.

Discover More

Removing Dashes from ISBN Numbers

ISBN numbers are used to denote a unique identifier for a published book. If you remove the dashes included in an ISBN, ...

Discover More

Trouble Recording Paste Special Formula

Sometimes, when you upgrade to a new version of Excel, you could run into a problem recording macros that you had no ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (menu)

Reorganizing Data

If you need to consolidate a single column of data into multiple columns of data, you'll love this macro. It provides a ...

Discover More

Skipping Hidden Rows in a Macro

As your macro processes information in a worksheet, you may want to make sure that it skips over rows that are hidden. ...

Discover More

Noting the Workbook Creation Date

You may want to add, to your worksheet, the date on which a particular workbook was created. Excel doesn't provide a way ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 - 0?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.