PTS Blog

Main menu:

PTS Utilities

Commercial Utilities developed by Peltier Technical Services

Waterfall Chart
Box and Whiskers


 

Excel Books

Books that I own and use while developing in Excel

Goods and Services

Excel or charting related products and services which I use or feel are worthwhile additions

Subscribe

Subscribe

Site search


Recent Posts

Recently Commented

Popular Posts

Archive


 

Categories


 

Creative Commons License
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

Extract Chart Data

by Jon Peltier
Peltier Technical Services, Inc., Copyright © 2008.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

This post presents a VBA procedure that extracts all data from a chart, and places it into a new worksheet. Why would you want to extract a chart’s data? Sometimes a chart gets its data from diverse sources, and you’d like to have the data in one place. You may receive a workbook that contains a chart, but the chart’s data is in a workbook which you don’t have access to. For whatever reason, this procedure comes in handy.

Sub ExtractChartData()
   Dim iSrs As Long
   Dim cht As Chart
   Dim srs As Series
   Dim ws As Worksheet

   If ActiveChart Is Nothing Then Exit Sub

   Set cht = ActiveChart
   Set ws = Worksheets.Add
   For iSrs = 1 To cht.SeriesCollection.Count
     Set srs = cht.SeriesCollection(iSrs)
     On Error Resume Next
     ws.Cells(1, 2 * iSrs).Value = srs.Name
     ws.Cells(2, 2 * iSrs - 1).Resize(srs.Points.Count).Value = _
         WorksheetFunction.Transpose(srs.XValues)
     ws.Cells(2, 2 * iSrs).Resize(srs.Points.Count).Value = _
         WorksheetFunction.Transpose(srs.Values)
   Next
 End Sub
 

The procedure merely extracts the data, it does not change the data source of the chart to the ranges in the new worksheet. If desired, you could embellish this macro, so it restores information such as chart type, series formatting (marker or fill style and colors, line or border styles and colors), axis types and scales, axis and chart titles, data labels, and more.

If you are not sure how to use this procedure, read How To Use Someone Else’s Macro.

Possibly Related Posts:

Bookmark and share this entry:
  • Digg
  • del.icio.us
  • Facebook
  • Technorati
  • TwitThis
  • StumbleUpon
  • Google
  • Reddit
  • MySpace

Comments

I welcome comments from my readers. If you have an opinion on this post, if you have a question or if there is anything to add, I want to hear from you. Whether you agree or disagree, please join the discussion.

Read the PTS Blog Comment Policy.


Comment from Clint
Time: Tuesday, August 26, 2008, 2:28 pm

Wow! I think this little utility is something that might come in very handy - thanks!


Comment from Haffy
Time: Thursday, August 28, 2008, 5:04 am

Thanks, Jon. I have to extract data from charts regularly and sorted out a workbook to do it - but your code is so much faster - one of those “Why on earth didn’t I try that?” moments.

Thanks again.


Comment from TV
Time: Thursday, September 4, 2008, 5:51 pm

Is there a series property or some other trick to get the address of the chart data (or at least a point)?


Comment from Jon Peltier
Time: Thursday, September 4, 2008, 6:23 pm

TV -

This can be done by parsing the series formula. John Walkenbach has code to do this:

A Class Module To Manipulate A Chart Series.

Write a comment





Subscribe without commenting

Create Excel dashboards quickly with Plug-N-Play reports.