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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB for formatting excel graph colours

Status
Not open for further replies.

johnbailey

Technical User
Jul 3, 2002
8
GB
Hi,
I'm having a problem creating the VB code which formats the colours in a graph depending on the outcome of another cell. Or to be able to format the graph to begin with to react to values on a conditional format basis.
Would appreciate the help.
Thanks
john
 
Have you tried to play with the Macro recorder ?
What have you so far ?
 
PHV,
Hi, trying to use an IF statement but haven't done one altering graphs before, I think the structure is wrong. Do you think an IF ELSE would be easier?
Thanks
John


Range("L284").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=TRUE,"
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).Points(2).Select
With Selection.Interior
.ColorIndex = 5
.Pattern = xlSolid
End With
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).Points(2).Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End Sub
 
john,

Here's an example of what can be done
Code:
Sub ColorTest()
'5 series each with 10 points
    For lRow = 1 To 5
        For iCol = 1 To 10
            With ActiveSheet.ChartObjects(1).Chart.SeriesCollection(lRow).Points(iCol).Interior
                Select Case Cells(lRow, iCol).Value
                    Case Is < 0
                        .ColorIndex = 5
                        .Pattern = xlSolid
                    Case Is = 0
                        .ColorIndex = 7
                        .Pattern = xlSolid
                    Case Is > 0
                        .ColorIndex = 9
                        .Pattern = xlSolid
                End Select
            End With
        Next
    Next

End Sub
:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top