+ Reply to Thread
Results 1 to 2 of 2

Dynamic Chart - Hide legend entry for unplotted series

  1. #1
    Registered User
    Join Date
    06-22-2010
    Location
    Airdrie, Scotland
    MS-Off Ver
    365
    Posts
    42

    Dynamic Chart - Hide legend entry for unplotted series

    Hi All,

    I have a dynamic chart, allowing me to select which series I wish to show. My problem is that, for any series I don't want shown, the series colour is still showing on the legend. I know I can select the colour on the legend and simply delete but is there some way (VBA?) that I can get this to happen automatically (by basing the colour on a cell value maybe?)?


    Thanks in advance.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,925

    Re: Dynamic Chart - Hide legend entry for unplotted series

    I know I can select the colour on the legend and simply delete but is there some way (VBA?) that I can get this to happen automatically
    Just about anything you can do manually in Excel can be done using VBA and automated. What is your skill level with VBA or other programming languages? How familiar are you with Excel's object model?

    The real difficulty, I think, with automating something like is not in deleting the legend entries, but in restoring the deleted legend entries. Microsoft did not provide a simple way to restore a legend entry once deleted. You essentially are forced to delete the legend entirely and then recreate the legend. So the first step in the procedure will be to remove the legend and recreate it. This is accomplished using the .haslegend property of the chart object. https://msdn.microsoft.com/en-us/lib.../ff840365.aspx

    Once you have the legend with all of the legendentries in place, then you need to loop through the seriescollection and identify which legendentries to delete. Once those are identified, then you can loop through the legendentries collection and delete the desired legendentries with the legendentry.delete method. The help file above has a menu on the left hand side that allows you to navigate through Excel's object model to learn the object model and what you can do with each object.

    Is a legend absolutely necessary? An easier approach might be to get rid of the legend entirely and use a data label on one of the points (first, last, high, or low depending on what will be most effective) for each series. https://support.office.com/en-us/art...9-e8109fdc1613
    https://support.office.com/en-us/art...rs=en-US&ad=US

    The main advantage that I see to using data labels instead of legend entries is that it will be much easier to maintain -- it may even completely eliminate the need for further maintenance. Unlike legend entries, data labels are only present when the labeled point is present. So, when a series is empty, the data label will not display. However, once data is entered into that series, the data labels will automatically reappear. Once set up, there would be no need for a VBA routine (or other method) to show/delete legend entries.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. [SOLVED] Removing Chart Legend Entry when Series Returns "NA()"
    By James McEwan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-02-2015, 09:49 AM
  2. [SOLVED] Dynamic chart with checkboxes hide/shoow series
    By michele82 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 05-23-2013, 12:26 AM
  3. [SOLVED] Exclude one data series from scatter chart legend (but not from the chart)
    By JayUSA in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 05-29-2012, 05:24 PM
  4. How do I hide 1 series in legend
    By wanluo in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 11-29-2007, 12:41 PM
  5. [SOLVED] Dynamic legend/series
    By judith in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-26-2006, 03:50 AM
  6. Hide series names for unused data from chart legend
    By Neil Goldwasser in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 02-10-2006, 03:15 PM
  7. How to hide a dummy series in a chart legend?
    By holg3r in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 07-14-2005, 04:04 AM

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