+ Reply to Thread
Results 1 to 21 of 21

macro for conditional format of sereis on chart

  1. #1
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Thumbs up macro for conditional format of sereis on chart

    Hi,

    I'll simplify what I need by the following:

    I have a range of data (A1:C60) which will be updated on daily basis, I plot range (A1:A60) vs. (B1:B60) on a chart and give my sereis one of 4 colors based on the value of range (C1:C60) which is 1,2,3,and 4.

    Now I need a macro please to give color for the point (A1,B1) based on the value of C1 and same for all data range down to bottom and to auto-update the chart whenever the data is updated.

    Appreciate support!
    Last edited by Ralem; 02-18-2011 at 06:29 AM.
    Cheers
    Ralem

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

    Re: macro for conditional format of sereis on chart

    Rather than a macro use a chart with 4 series and formula to determine which value is used for each data point/series.
    http://peltiertech.com/Excel/Charts/...nalChart1.html

    Using Named ranges or List/Table objects will allow for automatic expansion of chart.
    http://peltiertech.com/Excel/Charts/Dynamics.html
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    Hi Andy,
    Thanks for the reply; actually I tried this idea before and it worked very well, but I need a macro this time cause I have more than 100 sereis/points.

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

    Re: macro for conditional format of sereis on chart

    Please Login or Register  to view this content.
    Adjust colorindex values to suit

  5. #5
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    Thanks a lot Andy, I'll try it right right away...

  6. #6
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    Hi Andy,

    This code is not conditional, is it? If you go back to my question, I need the sereis to be colored based on the values given in the 3d column...
    I have 4 cases/groups of colors but I have 60 sereis which will increase evey day, colors to be given based on the sereis group.

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

    Re: macro for conditional format of sereis on chart

    Actually my code checks the Y value for conditional colouring

    If the value to be checked is in adjecent cell will will need to define a range object to reference it

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    No need to tell in the code what data is in the range? like (and that's exactly what I need, and for more details I have texts in the range not number) so it'll be:
    if the value in the range is "text1" then color sereis with....
    if the value in the range is "text2" then color sereis with....
    if the value in the range is "text3" then color sereis with....
    if the value in the range is "text4" then color sereis with....

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

    Re: macro for conditional format of sereis on chart

    Obviously my mindreading powers are failing me.

    Post an example workbook so I don't have to second guess.

  10. #10
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    Thanks Andy for your patience, sorry I had to be clear and specific from the beginning.

    OK, I'm attaching an example now, I have the texts in column D which are grouping my data, when updating the data with adding a point it'll be given a name in column A and one of the texts in column D.
    the macro will do the following:

    over range A2:D100, the series points will be (Bi,Ci)
    Ai is the name of each series, Di is the group of that series

    if Di="a" then series is blue circle and show series name to the left
    if Di="b" then series is red circle and show series name to the left
    if Di="c" then series is black triangle and show series name to the left
    if Di="d" then series is blue square and show series name to the left
    if Di="e" then series is red square and show series name to the left


    I make a series for each point cause I need to show its name on the chart.

    Please check the attachment,
    Appreciate support!
    Attached Files Attached Files
    Last edited by Ralem; 02-17-2011 at 03:11 AM.

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

    Re: macro for conditional format of sereis on chart

    The attached has both approaches.

    Code for multiple single point series and multiple series with multiple points.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    Thanks Andy, this macro is great, but need to add something more if you don't mind:
    On the "singlepoint" one, I changed ranges to: Range("A2:A100") and Range("D2:D100") which are blank below row 14; I'll have all this range as blank series on the chart but need this macro to auto run when these blank rows are filled with data.

    for the "multipoits" macro; it gives error message, it tells that <Unable to get the HasDataLabel Property of the point class>

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

    Re: macro for conditional format of sereis on chart

    When I clear the cells A7:D7 and A10:D14 both sets of codes work as expected.

    You need to post example of failing workbook.

  14. #14
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    It's OK now, please look at the first part of my last post regarding the "singlepoint" macro.

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

    Re: macro for conditional format of sereis on chart

    Use the worksheet change event to run the macro.

    Please Login or Register  to view this content.
    right click sheet tab and pick View Code. Paste above code.

  16. #16
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    But I have many things in my spreadsheet will change when used by users and then in each time the macro will run, can we make it run only when the specific range (A2:A100) is changed.

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

    Re: macro for conditional format of sereis on chart

    Did you look at the code? Have you tried it?

    The Intersect test restricts updates to changes in the ranges A2:A100 and D2:D100.

  18. #18
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    didn't try it, just liked to clarify that point... I'll try it...
    Last edited by Ralem; 02-18-2011 at 05:40 AM.

  19. #19
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    Andy, when I edit only the cell B15 it goes to the macro page and a message pops up with:
    Compile Error:
    Sub or Function not defined

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

    Re: macro for conditional format of sereis on chart

    because I misplet intersect.

    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    04-10-2010
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    148

    Re: macro for conditional format of sereis on chart

    Everything is OK now,
    You're very kind and patient Andy
    Thank you very very very much, you helped me a lot

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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