Get underlying range address of a chartobject in Excel

Enter1

New Member
Joined
Sep 3, 2014
Messages
8
Hello All,
Im currently working on a project where I have excel files that have atleast 60-100 graphs each for different parameters. I wanted to list the underlying cell location of these charts in a separate excel sheet. I know I can do the opposite using VBA (specify where a chart can be placed at a desired range in a sheet).
For example I have a graph - chartobject above a range - E3:I13 , I would like to know if we can use VBA to get that underlying range address.

Unable to find a fix to this:(, if one of you can help then that would be of great help:).

Thanks.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,450
This creates a worksheet with a list of all your charts and their locations.

Code:
[color=darkblue]Sub[/color] Chart_List_Ranges()
    [color=darkblue]Dim[/color] wsDest [color=darkblue]As[/color] Worksheet, ws [color=darkblue]As[/color] Worksheet, cht [color=darkblue]As[/color] ChartObject, i [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Set[/color] wsDest = Sheets.Add(After:=Sheets(Sheets.Count))
    wsDest.Range("A1:C1").Value = Array("Sheet", "Chart", "Range")
    i = 1
    [color=darkblue]For[/color] [color=darkblue]Each[/color] ws [color=darkblue]In[/color] Worksheets
        [color=darkblue]If[/color] [color=darkblue]Not[/color] ws [color=darkblue]Is[/color] wsDest [color=darkblue]Then[/color]
            [color=darkblue]For[/color] [color=darkblue]Each[/color] cht [color=darkblue]In[/color] ws.ChartObjects
                i = i + 1
                wsDest.Range("A" & i).Value = ws.Name
                wsDest.Range("B" & i).Value = cht.Name
                wsDest.Range("C" & i).Value = Range(cht.TopLeftCell, cht.BottomRightCell).Address(0, 0)
            [color=darkblue]Next[/color] cht
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] ws
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 

Enter1

New Member
Joined
Sep 3, 2014
Messages
8
Excellent , thanks a lot "AlphaFrog" for the solution . It works like magic!!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,651
Messages
5,832,908
Members
430,175
Latest member
Sheenamarie

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
Top