Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Colour Bars in Chart 1

Status
Not open for further replies.

Igwiz

Technical User
Jun 3, 2003
88
CA
Having been referred from another forum, can someone give me a clue on a VBA way of doing this. I am aware of the spreadsheet workarounds but want to do it with code. Thanks.

------
Hi all,

On a bar chart, I would like to loop through each of the data points and if the value is say <10, then change the colour of the bar to say red. I know how to change the colour in vba by looping through SeriesCollection(1).Points but how do I test the data value it is associated with.
i.e. what is the property associated with Point that returns the datavalue

Many thanks.

Ig
 
Hi,

Here's a VBA solution to your problem. It assumes
1. that the data range of values has a Range Name of Value
2. that there is one chart on the sheet
3. that there is one series...
Code:
Sub ChangeColors()
    With ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
        i = 1
        For Each p In .Points
            If Range(&quot;Value&quot;)(i) > 10 Then
                p.Interior.ColorIndex = 3
            Else
                p.Interior.ColorIndex = 4
            End If
            i = i + 1
        Next
    End With
End Sub


Skip,
Skip@TheOfficeExperts.com
 
Brilliant Skip - many thanks for your help! :)
 
Igwiz, seeing as Skip has resolved your problem, it would be worth rewarding him with a star otherwise he may become disheartened ;-)

You can do this by clicking the &quot;Mark this post as a helpful/expert post!&quot; just after Skip's post.

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top