+ Reply to Thread
Results 1 to 14 of 14

VBA Assign Chart Series Name

  1. #1
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    VBA Assign Chart Series Name

    How do you insert the Chart Series Name by code?

    Manually, this can be accomplished via "Select Data Source": select "Name", select cell(s), done.

    I'd like the Series Name to be highlighted with the red frame, when the chart is selected.
    Just like the Categories and Values are highlighted in purple and blue.

    Tried this, doesn't work:

    Please Login or Register  to view this content.
    This is the create chart code:
    Please Login or Register  to view this content.
    Thank you!
    Last edited by briskie; 04-03-2024 at 12:50 PM.

  2. #2
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA Assign Chart Series Name

    Found this code by Jon Peltier:
    https://peltiertech.com/assign-chart...ries-with-vba/
    It lets you select a range that contains the series name via InputBox.

    Please Login or Register  to view this content.
    So I added these lines to my create chart code, hoping it would do. Nothing happened.
    Please Login or Register  to view this content.
    What am I missing?

    Thanks Jon!
    Thanks everyone!

  3. #3
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,313

    Re: VBA Assign Chart Series Name

    You appear to be a "" missing after C1 and before )
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  4. #4
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    257

    Re: VBA Assign Chart Series Name

    You're using the wrong property.

    ".Name" only RETURNS the name of the chart, not sets it.

    You need to use ".FullSeriesCollection(1).Name"

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA Assign Chart Series Name

    Hi Torachan.
    Thanks, corrected that, didn't help.

  6. #6
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA Assign Chart Series Name

    Hi PrizeGotti,
    ".FullSeriesCollection(1).Name" causes an Automation Error.

  7. #7
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    257

    Re: VBA Assign Chart Series Name

    Not on my machine, did you copy and paste the code I posted?

  8. #8
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA Assign Chart Series Name

    Had to restart Excel, now your code works, thanks.
    But the red frame is still missing.

  9. #9
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA Assign Chart Series Name

    In the "Select Data Source" window, the "Name" is still blank/empty:

  10. #10
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA Assign Chart Series Name

    I've also tried to record a macro, but Excel won't allow that in the "Select Data Source" window, saying "Application.CutCopyMode = False".

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: VBA Assign Chart Series Name

    If you want to set the series name to a cell reference then use

    Please Login or Register  to view this content.
    the use of .Name in your first code was trying to set the name of the chart, which you can't do. The name is made up of sheet and object name

    You can set the name of the chart object using
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  12. #12
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA Assign Chart Series Name

    Andy, thank you so much!

    One thing I've noticed:

    If the series name is set as text, the create code creates the chart in a way, that the categories and values are highlighted (blue, purple)
    - if you click on the chart area
    - if you click on the plot area
    - if you click on the slices/bars

    If the series name is set as a range (with your code), series name, categories and values are only highlighted (red, blue, purple)
    - if you click on the slices/bars

    Might there be an "easy fix" to this as well?

    Thank you!

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: VBA Assign Chart Series Name

    The range highlighting is dependent on the Source data range reference. If this is a set of contiguous areas then you should get all 3 areas highlighted. Names/Category labels/Data values.

    Because your series name range is position above the category label range it can not automatically unravel the layout. It can only do that when you select a specific data series.

    Ideally the data layout would be

    Category Labels
    SeriesName DataValues

  14. #14
    Registered User
    Join Date
    03-10-2024
    Location
    Berlin
    MS-Off Ver
    mac2016
    Posts
    94

    Re: VBA Assign Chart Series Name

    Oh, ok. Good to know – thank you for explaining!
    Last edited by briskie; 04-06-2024 at 09:09 AM.

+ 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] Matching 'Chart Series title' to equation driven cells to set the series line colour
    By mattydboom1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-15-2020, 09:36 AM
  2. Replies: 2
    Last Post: 02-19-2017, 07:52 PM
  3. Delete Pivto Chart Series when certain word/text is found in the Series Name
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2016, 03:19 PM
  4. Apply format of a series to a similar series in a different chart
    By Skiffie in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 02-05-2013, 10:43 PM
  5. Chart front-to-back series display if series are different chart types
    By Exconomist in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 10-06-2012, 06:49 AM
  6. mixing column chart types for series and macro series?
    By riwiseuse in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 03-30-2010, 05:27 PM
  7. [SOLVED] chart data series -- plot a table as a single series
    By hjc in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 09-20-2005, 01:05 PM

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