VBA Code Help - Relating to Colour Fill of Pie Charts

Steaky

New Member
Joined
May 22, 2013
Messages
4
Hi all,

Looking for some guidance. I'm wondering if anyone knows of any way to edit this VBA code so that it works with cells that are coloured via conditional formatting?

If not, is it possible to bypass this issue (currently, my poor pie chart is now blank!) by using a VBA code to colour in the cells that my pie chart refers to?

Code:
 Sub ColorPies()
    Dim cht As ChartObject
    Dim i As Integer
    Dim vntValues As Variant
    Dim s As String
    Dim myseries As Series
     
        For Each cht In ActiveSheet.ChartObjects
            For Each myseries In cht.Chart.SeriesCollection
     
                If myseries.ChartType <> xlPie Then GoTo SkipNotPie
                s = Split(myseries.Formula, ",")(2)
                vntValues = myseries.Values
               
                For i = 1 To UBound(vntValues)
                    myseries.Points(i).Interior.Color = Range(s).Cells(i).Interior.Color
                Next i
SkipNotPie:
            Next myseries
        Next cht
    End Sub


Thank you!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Instead of trying to read the Conditional Formatting (CF) color, you could code your macro to test for the same "conditions" used in the CF formulas.

Replace this line...
myseries.Points(i).Interior.Color = Range(s).Cells(i).Interior.Color
...with the same CF formulas whatever they may be.
 
Upvote 0
I really don't know much at all about macro codes.


If my conditional formatting in a cell is to colour the cell based on the contents of another cell, how would this look in code?


I appreciate any help :)
 
Upvote 0
I really don't know much at all about macro codes.


If my conditional formatting in a cell is to colour the cell based on the contents of another cell, how would this look in code?


I appreciate any help :)


Can you show your CF formua(s) and what color they have?
 
Upvote 0
I'm at work at the minute, it would maybe be best if I attach my worksheet when I get home.


My conditional formatting is along the lines of (from memory):


In cell B9:B13: if E2:E6 = 1, colour green


If E2:E6 = 0, colour red.


B9 is looking up E2, B10 looks up E3 and so on.


Thank you for helping me with this!
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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
Back
Top