Hello,
I need help in conditionally formatting a chart.
I the attached file I need to color Item2's Series red if value is below 40 and green if above
How this can be done?
Thanks for the help
Last edited by Bob@Sun; 04-08-2010 at 06:18 AM.
Being a pivot chart you can not use the usual approach of extra series.
Instead you need event code. right click the sheet tab for the chart and pick view code. Paste the following.
Private Sub Chart_Calculate() Dim objSeries As Series Dim lngPoint As Long Set objSeries = ActiveChart.SeriesCollection(2) For lngPoint = 1 To objSeries.Points.Count If Application.WorksheetFunction.Index(objSeries.Values, 1, lngPoint) > 40 Then objSeries.Points(lngPoint).Format.Fill.ForeColor.RGB = RGB(0, 255, 0) Else objSeries.Points(lngPoint).Format.Fill.ForeColor.RGB = RGB(255, 0, 0) End If Next End Sub
Hi Andy,
The code you provided gives me an error in this part:
Error: Run-Time Error '438'. Object doesn't support this property or methodobjSeries.Points(lngPoint).Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
Any ideas?
Thanks for the help!
Sorry, that was xl2007 code.
Private Sub Chart_Calculate() Dim objSeries As Series Dim lngPoint As Long Set objSeries = ActiveChart.SeriesCollection(2) For lngPoint = 1 To objSeries.Points.Count If Application.WorksheetFunction.Index(objSeries.Values, 1, lngPoint) > 40 Then objSeries.Points(lngPoint).Interior.ColorIndex = 14 Else objSeries.Points(lngPoint).Interior.ColorIndex = 3 End If Next End Sub
Hi Andy,
The code is great!
I was wondering how can I change the code to refere if to a cell in another sheet?
Private Sub Chart_Calculate() Dim objSeries As Series Dim lngPoint As Long Set objSeries = ActiveChart.SeriesCollection(1) For lngPoint = 1 To objSeries.Points.Count 'If Application.WorksheetFunction.Index(objSeries.Values, 1, lngPoint) > 2 Then If Sheets("Calculations").Range(AI4).Value < 1 Then objSeries.Points(lngPoint).Interior.ColorIndex = 14 Else objSeries.Points(lngPoint).Interior.ColorIndex = 3 End If Next End Sub
Can you help me with this Please?
You need to provide more information as currently all points in the series will be tested against a single cell.
You need quotes around the cell address.
If Sheets("Calculations").Range("AI4").Value < 1 Then
Hi Andy,
So here is the scenario:
With the layout in the sample chart, I need to color the column for Item 7 based on the value in Column K in sheet1:
If Value is 1 - red , if 2 - green
Can you do that?
Assuming each record is discrete then this should work.
Private Sub Chart_Calculate() Dim lngIndex As Long Dim strOuterLabel As String Dim strInnerLabel As String Dim strLabel As String Dim strTemp As String Dim lngRow As Long On Error Resume Next For lngIndex = 1 To ActiveChart.SeriesCollection(1).Points.Count strLabel = Application.WorksheetFunction.Index(ActiveChart.SeriesCollection(1).XValues, 1, lngIndex) strInnerLabel = Split(strLabel, Chr(10))(0) strTemp = Trim(Split(strLabel, Chr(10))(1)) If Len(strTemp) > 0 Then strOuterLabel = strTemp End If If strInnerLabel = "Item 7" Then Debug.Print "Check Value ", strInnerLabel, strOuterLabel lngRow = Application.WorksheetFunction.Match(strOuterLabel, Sheet1.Range("A1:A12"), 0) If Sheet1.Cells(lngRow, 11) = 1 Then ActiveChart.SeriesCollection(1).Points(lngIndex).Interior.ColorIndex = 3 Else ActiveChart.SeriesCollection(1).Points(lngIndex).Interior.ColorIndex = 14 End If End If Next End Sub
Many thanks, it is perfect!
I still have some questions that are related to the same Pivot Table. Tell me if I need to start a new Post or keeping the discussion here is Ok.
So, with the same file and layout, is it possible to remove from the chart Items which value is 0?
In the sample file, I have Values in F2, D3 and H3 = 0 and I need in the chart those Items to be removed. Item 4 for Name 1, Item 2 for Name 2 and Item 6 for Name 2 should not be on the chart.
I appreciate your help Andy!
Bob
I don't think you can remove those zero items.
It's all or nothing. If you try to hide Item4, for example, all Item4 details will go.
If you restructure your data and don't include the zero records then it will do it automatically.
I can't restructure the data, thanks for the help anyway.
Everything else is perfect!
Cheers
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks