+ Reply to Thread
Results 1 to 25 of 25

Color series on a line chart based on cell values.

  1. #1
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Color series on a line chart based on cell values.

    Hello friends,
    I have this cool script which changes multiple series widths on a line chart based on values specific for each series. Can I ask you to help me add the possibility to color each line according to the integer assigned to each series? I need to set the color of each line based on similar row of integers - 1 (for red), 2 (for blue) I have attached the workbook.
    hopefully this is possible.....I understand I need to set the color with rgb?
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Color series on a line chart based on cell values.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    if that works that is the most beautiful code I have seen !))) let me check!

  4. #4
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    I understand this is a separate macro to the first one which changes line thickness?

  5. #5
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    just run this macro - shows element not found and when I press debug - excel crashes - can you please check? Can I specify exactly which integer is assigned which color in the macro? - eg 1 is blue?


    also do think this this macro can be merged with the weights adjusting macro? or it is better to keep them separate?
    Last edited by zealot; 11-11-2020 at 02:07 AM.

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

    Re: Color series on a line chart based on cell values.

    Here is an alternative

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  7. #7
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    nice let me check

  8. #8
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    Quote Originally Posted by Andy Pope View Post
    Here is an alternative

    Please Login or Register  to view this content.
    By the way, Andy - this is a separate macro right - do you think it can be combined with the thickness macro?

  9. #9
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    It actually works!!! - this is what i call beautiful programming!)

  10. #10
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    maybe this can be an overkill but can this macro be updated to color the background of any data labels for each series that are present on the chart with the same color as the line?

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

    Re: Color series on a line chart based on cell values.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    that is really amazing - this will go through all data points? can it be made to run only through the existing points? thanks a lot!

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

    Re: Color series on a line chart based on cell values.

    It goes through all data points and formats those that have a data label, hence the use of HasDataLabel within the For Each loop.

  14. #14
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    Dear Andy - thank you for your generous help - I noticed with the last macro it can only update labels which have no background -fr some reason it does not update background of the label when I run the macro again - can you please take a look?

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

    Re: Color series on a line chart based on cell values.

    You need to post an example file.
    I tested on your original file by adding data labels to series 1 and data label to last point of series 2

  16. #16
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    it works - just had to enable visibility of all overlaying charts- please take a look at the chart Andy
    https://www.temporary-url.com/4F87A

    I think I have 5 or so charts overlaying each other - can you recommend an easy way to export all the charts once one to a predefined png file (file name will be in cell a1)?

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

    Re: Color series on a line chart based on cell values.

    There is no simple way to export images from excel.

    You could copy the grouped charts to powerpoint, paste as image and then export from there.

    Or do a screen capture and tidy up in paint, or some other image editor

  18. #18
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    Thank you Andy - maybe you have seen a way to quickly export Camera view to png file? the camera woudl render all overlaid charts as one image and it can be exported this way

  19. #19
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    I have attached the workbook which has two objects - chart and camera picture referencing this chart - maybe you can recommend how to export the camear picture as the png file? The png file name should be taken from a cell - eg. image1..if you wish I can create a separate topic for this question.
    Attached Files Attached Files
    Last edited by zealot; 11-12-2020 at 07:13 AM.

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

    Re: Color series on a line chart based on cell values.

    There is no native picture export in excel.

    One way is to use a chart object to hold the image and use the Export method of the chartobject

    There is code example in this
    https://andypope.info/vba/gex.htm

  21. #21
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    I see - thank you - wanted to ask if there is a way to change picture name based on a cell value?

  22. #22
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    also - can your addin be invoked by a keyboard shortcut?

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

    Re: Color series on a line chart based on cell values.

    If your chart was a single chart, rather than 5 stacked on top of each other you could simply use the export method.

    You don't need to use the addin but you can make use of the code inside it to create your own routine.

    You can name the chart object
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    11-09-2006
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    200

    Re: Color series on a line chart based on cell values.

    thank you Andy - can I name the camera image object?

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

    Re: Color series on a line chart based on cell values.

    Yes you just need to be able to identify the shape and then change it's name.

+ 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. Chart with series in color based on value
    By vijanand1279 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2018, 04:01 AM
  2. Replies: 5
    Last Post: 03-28-2015, 03:48 PM
  3. Line Chart Multiple Data Series Format Same Color
    By mark.dehoog in forum Excel General
    Replies: 8
    Last Post: 02-16-2015, 05:15 AM
  4. Macro to updata chart and color 2 line(even and odd series)
    By proxima in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2013, 09:33 AM
  5. Set chart series color to match series legend entries font color
    By Equipoise in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-03-2013, 07:33 AM
  6. Line Chart series showing values for NA()
    By dcgrove in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 02-22-2012, 04:45 AM
  7. Same color for groups of series (line chart)
    By dogbiskit in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 06-20-2008, 01:01 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