+ Reply to Thread
Results 1 to 7 of 7

VBA: How to automatically update data range in a chart?

  1. #1
    Registered User
    Join Date
    02-10-2022
    Location
    Chicago
    MS-Off Ver
    macbook
    Posts
    7

    VBA: How to automatically update data range in a chart?

    Hi, all! I have spent hours on this but have not figured it out...

    I have a data table of sales/costs/profits from 2015 to 2022. What I want to achieve: after users input start year (C2) and end year (C3), the line graph would automatically include the data from start year to end the year. For example, with the start year of 2016 and an end year of 2021, the chart only shows these data.

    Anyone can help? Thank you!!
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: How to automatically update data range in a chart?

    You need to create a parallel set of data that is used for the chart, which uses formulas to determine what data to include. See attached.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    02-10-2022
    Location
    Chicago
    MS-Off Ver
    macbook
    Posts
    7

    Re: How to automatically update data range in a chart?

    Hi, 6StringJazzer, thank you for answering my question! One follow-up: it seems the graph still leaves space for blank cells, is there a way to ignore the blank cells? Thanks!

  4. #4
    Registered User
    Join Date
    02-10-2022
    Location
    Chicago
    MS-Off Ver
    macbook
    Posts
    7

    VBA: How to automatically update data range in a chart?

    Hi, all! I have spent hours on this but have not figured it out...

    I have a data table of sales/costs/profits from 2015 to 2022. What I want to achieve: after users input start year (C2) and end year (C3), the line graph would automatically include the data from start year to end the year. For example, with the start year of 2016 and an end year of 2021, the chart only shows these data.

    Anyone can help? Thank you!!
    Attached Files Attached Files

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,072

    Re: VBA: How to automatically update data range in a chart?

    Thread moved to the VBA section. Please don't open duplicate threads - your other thread on this has been closed and the post from it copied here. Thanks.
    Last edited by AliGW; 03-11-2022 at 04:03 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  6. #6
    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,477

    Re: VBA: How to automatically update data range in a chart?

    You don't need VBA for this. Just create Dynamic Named Ranges for years, sales, costs and profits. Then use those in the chart rather than static ranges.

    See the updated example. The DNR are described in rows 10 to 13. If you are using Excel 365, take the comments off to see them work in real time.
    Attached Files Attached Files
    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


  7. #7
    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,477

    Re: VBA: How to automatically update data range in a chart?

    Is this now resolved?

+ 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. How to automatically update data range in a chart using VBA?
    By jubingge in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2022, 03:54 AM
  2. Replies: 0
    Last Post: 02-04-2022, 02:36 AM
  3. Excel 2013. Automatically update chart range
    By kbdb in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-13-2016, 02:49 PM
  4. Replies: 2
    Last Post: 02-01-2013, 02:53 AM
  5. How to update chart automatically as new data added?
    By hmgrts in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 07-01-2009, 10:28 AM
  6. [SOLVED] how do i get the data in a chart to automatically update?
    By kinjamyhaz in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 08-14-2006, 10:45 AM
  7. [SOLVED] How do I automatically update a chart range in Excel
    By Quinton in forum Excel General
    Replies: 1
    Last Post: 07-27-2005, 07:57 AM

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