+ Reply to Thread
Results 1 to 22 of 22

Conditional Formats in Charts

Hybrid View

  1. #1
    Registered User
    Join Date
    09-08-2009
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    74

    Conditional Formats in Charts

    I am trying to create a chart in excel which automatically updates from green to red and vice versa.

    I have attached a copy of my work, its self-explanatory.

    But here is what I am after:

    Cells B32, 33 and Cells C32, 33 are conditionally formatted.

    Conditions:

    If the expense is greater than the income then = RED

    If expense is less than income then = GREEN

    This is still in its phase 1 so if anyone has ideas on how to improve this then that would be great.

    Thank You in advance
    Attached Files Attached Files
    Last edited by Jazzy Max; 09-27-2009 at 07:43 PM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Conditional Formats in Charts

    Hi,
    there are solutions at Jon Peltier's site

  3. #3
    Registered User
    Join Date
    09-08-2009
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Conditional Formats in Charts

    I cant seem to apply that to these charts..

    Any solution at all?

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

    Re: Conditional Formats in Charts

    Don't use the 3d style of charts. You will have to use code otherwise.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    09-08-2009
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Conditional Formats in Charts

    Hi Andy,

    Thank you for replying.

    Would it be possible for you to show me the starting script(s) to the macro?

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

    Re: Conditional Formats in Charts

    Sub FormatChart()
    
        Dim lngPoint As Long
        
        With ActiveSheet.ChartObjects(1).Chart
            ' make both bars the same
            .SeriesCollection(2).Format.Fill.ForeColor.RGB = .SeriesCollection(1).Format.Fill.ForeColor.RGB
            
            For lngPoint = 1 To .SeriesCollection(1).Points.Count
                If Application.WorksheetFunction.Index(.SeriesCollection(2).Values, lngPoint) < _
                   Application.WorksheetFunction.Index(.SeriesCollection(1).Values, lngPoint) Then
                   ' make expense Red
                   .SeriesCollection(2).Points(lngPoint).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
                End If
            Next
        End With
        
    End Sub

  7. #7
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Conditional Formats in Charts

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  8. #8
    Registered User
    Join Date
    09-08-2009
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Conditional Formats in Charts

    Hi Andy, thank you for your help so far, I really appreciate it.

    I have tried tweaking the macro a bit to show the expenses are red if they exceed the income...I am unable to do so for both sides?

    Any suggestions?

    thank you

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

    Re: Conditional Formats in Charts

    Can you post the tweaks you have made.

  10. #10
    Registered User
    Join Date
    09-08-2009
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Conditional Formats in Charts

    Well I was trying to change the columns that go red, the switch between red and black.

    I have tried entering 'Green' where it says 'Red' (in the macro) I have tried:

    With ActiveSheet.ChartObjects(1).Chart
    ' make both bars the same
    .SeriesCollection(2).Format.Fill.ForeColor.RGB (155,0,2) = .SeriesCollection(1).Format.Fill.ForeColor.RGB (160,8,5)

    Just random colours for now, but the columns that I wanted to change weren't changing..

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

    Re: Conditional Formats in Charts

    That line does not make sense.

    To set the colour of a column use
    .SeriesCollection(2).Format.Fill.ForeColor.RGB  = RGB(155,0,2)
    
    .SeriesCollection(1).Format.Fill.ForeColor.RGB = RGB(160,8,5)

  12. #12
    Registered User
    Join Date
    09-08-2009
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Conditional Formats in Charts

    Cool.

    Thanks

    I will have to play around with this a little bit. Somehow, I dont see what I want (you have done great) I need to re-do the conditions.

    I wanted it to turn out the opposite to what it is now..

    If the income is less than the expenses then both columns should be red

    If the income is more then both columns can be green...?

    Does that make sense to you, any suggestions on how I can improve this?

    Thank You

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

    Re: Conditional Formats in Charts

    Just add another line to format the other series,

    ' income less than expense
                If Application.WorksheetFunction.Index(objSeries1.Values, lngPoint) < _
                   Application.WorksheetFunction.Index(objSeries2.Values, lngPoint) Then
                   ' make income Red
                   objSeries1.Points(lngPoint).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
                   ' make expense Red
                   objSeries2.Points(lngPoint).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
                End If

  14. #14
    Registered User
    Join Date
    09-08-2009
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Conditional Formats in Charts

    Great I will be testing this out shortly.

    One last query, is it possible for these graphs to change colour automatically?

    i.e. is there a non-macro way to do this?

    Because I will want to present 2 versions, one with a macro and one without a macro...

    Andy, I really appreciate your assistance.

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

    Re: Conditional Formats in Charts

    To do it without macros you first need to use a 2d chart style. You can use 3d but you have no control over the data label position.

    You then need to layout data out slightly differently to add padding columns.
    The column gap is set to zero to make the columns appear next to each other.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    09-08-2009
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Conditional Formats in Charts

    Amazing! You are a genius.

    Thank you for all your efforts I now have both graphs going well and that is all thanks to you.

    How do I add you in my list? If thats ok with you.

+ 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