+ Reply to Thread
Results 1 to 5 of 5

Excel VBA : Chart : How do you determine, programmatically the chart range

  1. #1
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Excel VBA : Chart : How do you determine, programmatically the chart range

    Despite searching Google, I don't seem to be able to find the answer to my question/problem.

    So, say a chart has a range something like:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    how would I return that range address?

    Rider: there are several charts on several sheets so, how would I loop through the sheets and, within each sheet, return the chart title and range address for each chart.

    I know that I can set the range using
    Please Login or Register  to view this content.
    but I need to be able to establish what it currently is in order that I can adjust it.

    Do I need to select the sheet and/or the chart (making it active) in order to test and set the range?

    Thanks in advance

    TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Excel VBA : Chart : How do you determine, programmatically the chart range

    Try this:
    Please Login or Register  to view this content.
    It loops through each chart on each worksheet - for each chart, it loops through each series, and extracts the range from the series FORMULA property. We then union the series ranges to provide the overall chart range.
    Last edited by Olly; 11-02-2016 at 08:40 AM. Reason: Added chart title
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Excel VBA : Chart : How do you determine, programmatically the chart range

    Perfick

    Bit of tweaking as a) not all sheets have charts, and b) not all charts have split ranges.

    But it does the trick

    Thank you.

    TMS

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Excel VBA : Chart : How do you determine, programmatically the chart range

    Quote Originally Posted by TMS View Post
    b) not all charts have split ranges.
    That doesn't actually make any difference - the series.formula property consists of 4 elements:
    1. Series Name
    2. XValues
    3. Values
    4. Plot Order

    These elements are comma separated, so the SPLIT function just identifies the range of XValues and Values.

    You may run into issues if the chart source is a direct data array, rather than a range... but that would also be easily handled.

    Glad it pointed you in the right direction - thanks for the feedback

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Excel VBA : Chart : How do you determine, programmatically the chart range

    That doesn't actually make any difference
    It seemed to; I needed to add on On Error Resume Next to cater for an error. Seemed OK after that.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Using a value from a range to determine chart source data
    By lillilil in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 05-14-2014, 10:30 AM
  2. excel pie chart and determine values from other tabs
    By jasonjhc in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 11-08-2013, 08:25 AM
  3. Programmatically Update a Chart object
    By SDruley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2011, 07:55 PM
  4. Update Chart table programmatically
    By JIBG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2007, 12:24 PM
  5. Programmatically determine Chart's data source
    By drussell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2006, 01:30 AM
  6. [SOLVED] Chart to worksheet programmatically -- coordinates?
    By Petr Prikryl in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-25-2005, 06:03 AM
  7. How to programmatically determine which rows are outlined using Excel VBA code
    By David in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-25-2005, 11:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1