Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
If
 
Posts: n/a
Default Conditional Colors for Charts

Good evening,
I have on a sheet with several graphs and I would like to execute the
procedure below automatically.

In advance thank you for the assistance
Yves



Sub ColorColumns()

Dim vntValues As Variant
Dim intSeries As Integer
Dim intPoint As Integer

With ActiveChart
For intSeries = 1 To .SeriesCollection.Count
With .SeriesCollection(intSeries)
vntValues = .Values
For intPoint = 1 To .Points.Count
If vntValues(intPoint) < 60 Then
..Points(intPoint).Interior.Color = vbRed
ElseIf vntValues(intPoint) = 60 And vntValues(intPoint) < 80 Then
..Points(intPoint).Interior.Color = vbYellow
Else
..Points(intPoint).Interior.Color = vbGreen
End If
Next
End With
Next
End With

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.charting
Andy Pope
 
Posts: n/a
Default Conditional Colors for Charts

Hi,

Assuming you just need your code to process all charts on the sheet
rather than just the active one.

'--------------------------------
Sub ColorColumns()

Dim vntValues As Variant
Dim intSeries As Integer
Dim intPoint As Integer
Dim objChart As ChartObject

For Each objChart In ActiveSheet.ChartObjects
With objChart.Chart
For intSeries = 1 To .SeriesCollection.Count
With .SeriesCollection(intSeries)
vntValues = .Values
For intPoint = 1 To .Points.Count
If vntValues(intPoint) < 60 Then
.Points(intPoint).Interior.Color = vbRed
ElseIf vntValues(intPoint) = 60 And _
vntValues(intPoint) < 80 Then
.Points(intPoint).Interior.Color = vbYellow
Else
.Points(intPoint).Interior.Color = vbGreen
End If
Next
End With
Next
End With
Next

End Sub
'----------------

If you want to run the automatically you will need to call the routine
from a worksheet event. Something like this placed in the sheet object

Private Sub Worksheet_Change(ByVal Target As Range)

' check if cell is in range containing chart data
If Not Intersect(Target, Range("A1:B10")) Is Nothing Then
ColorColumns
End If

End Sub

Cheers
Andy

If wrote:
Good evening,
I have on a sheet with several graphs and I would like to execute the
procedure below automatically.

In advance thank you for the assistance
Yves



Sub ColorColumns()

Dim vntValues As Variant
Dim intSeries As Integer
Dim intPoint As Integer

With ActiveChart
For intSeries = 1 To .SeriesCollection.Count
With .SeriesCollection(intSeries)
vntValues = .Values
For intPoint = 1 To .Points.Count
If vntValues(intPoint) < 60 Then
.Points(intPoint).Interior.Color = vbRed
ElseIf vntValues(intPoint) = 60 And vntValues(intPoint) < 80 Then
.Points(intPoint).Interior.Color = vbYellow
Else
.Points(intPoint).Interior.Color = vbGreen
End If
Next
End With
Next
End With

End Sub



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Format Not Working KMH Excel Discussion (Misc queries) 0 December 22nd 05 05:32 PM
Conditional formula - language needed gamebird Excel Worksheet Functions 7 October 10th 05 11:48 PM
Conditional Formatting Question - Different Cell Colors?? olimits7 Excel Discussion (Misc queries) 2 August 10th 05 04:05 PM
how can i use colors in conditional formulas if i want the result. kshaheen Excel Discussion (Misc queries) 1 March 22nd 05 10:09 AM
Conditional formatting not available in Excel BAB Excel Discussion (Misc queries) 2 January 1st 05 03:33 PM


All times are GMT +1. The time now is 08:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"