VBA conditional formatting on Pivot Charts?

Pebbaroo

New Member
Joined
Feb 24, 2016
Messages
2
Hi,

I'm trying to create a dashboard with a number of Pivot Charts. Ideally, I want to include some code in the work sheet that updates the bar colours of the chart depending on the value of the Pivot Chart (red when it's negative, blue when it's positive).

The dashboard is a visual representation of the outcome of a number of experiments we are running on multivariate testing. The experiments are included in the Pivot Charts as filters, which update the charts with the relevant data for that particular experiment. Each experiment has a different number of variants, meaning creating a 'normal' chart from the pivots first will not work because I need it to be able to pick up the varying number of potential rows, and ignore the 'empty' rows if no data is there.

This is the code I was using on the charts before I turned them into pivots (it was working back then). Is there a way of achieving this once they are pivot charts?


Code:
Dim s As Series
Dim i As Long


ActiveSheet.ChartObjects("Chart 41").Activate
    For Each s In ChartObjects("Chart 41").Chart.SeriesCollection


            For i = 1 To s.Points.Count
                If s.Values(i) < 0 Then
                s.Points(i).Interior.Color = RGB(192, 80, 77)
                Else
                s.Points(i).Interior.Color = RGB(75, 172, 198)
                End If
            Next i
    Next s
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Watch MrExcel Video

Forum statistics

Threads
1,123,088
Messages
5,599,664
Members
414,325
Latest member
kfg1287

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top