Get Source Data Range for a Chart

ttt123

Board Regular
Joined
May 31, 2006
Messages
120
Office Version
  1. 365
Platform
  1. Windows
Hello,
I'm try to figure out how to find what the source data range a chart refers to is, but there isn't an obvious property or method to get this. Does anyone know how to do it? There is a Chart.SetSourceData but no Chart.GetSourceData.

Thanks,
Taylour

Code:
Sub test()
    Dim cht As Chart, rngSourceData As Range
    For Each cht In ActiveSheet.Charts
        'This method doesn't exist.
        'Set rngSourceData = cht.GetSourceData
        If Not (Intersect(rngSourceData, Range("A1:M8")) Is Nothing) Then
            cht.Delete
        End If
    Next cht
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
This property is not exposed in VBA, probably for good reason. It doesn't take much to make this range too difficult to display.

You could, of course, loop through the series of a chart, parse the SERIES formulas of each series to get the ranges that contain name, X values, and Y values, then merge these ranges together. Note that Excel would not have showed a chart source data range in many cases:

1. Series don't all have the same X values.
2. Series don't all have the same number of points.
3. Series ranges do not fit into a rectangle (i.e., rows of data don't all stop and start in the same columns, or columns don't all stop and start in the same rows).
4. Series are not plotted in the order that their ranges appear in the worksheet.
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top