Pie charts to match conditioning formatting colors of cell

taffjohn

New Member
Joined
Oct 18, 2018
Messages
4
Hello

Im very new to all this so sorry if i haven't come across correct.

I have a macro that changes my chart colors basted on the conditional formatting of of a cell.

the problem i have is that i have to run the macro manually and i would like it to work automatically soon as the cell connected with chart changes color the chart updates and matches the colour.

THE CODE (a very kind person done for me)
Code:
Sub colourTheCharts()
    Dim co As ChartObject
    Dim sourceData As Range
    Dim n As Long
    Dim ser As Series
    Dim seriesFormula As String
    
    For Each co In ActiveSheet.ChartObjects
        Set ser = co.Chart.SeriesCollection(1)
        seriesFormula = Mid$(ser.Formula, 10)
        seriesFormula = Left$(seriesFormula, InStr(seriesFormula, ",") - 1)
        Set sourceData = Application.Range(seriesFormula)
        
        For n = 1 To ser.Points.Count
            With ser.Points(n).Format.Fill
                .Visible = True
                .Solid
                .ForeColor.RGB = sourceData.Cells(n).DisplayFormat.Interior.Color
            End With
        Next n
        
    Next
End Sub
 
Last edited by a moderator:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to the forum. :)

Please take a minute to read the forum rules on cross-posting and comply with them (by adding a link to your post in the other forum). Thanks.

Also, thanks for calling me "very kind". ;)
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,484
Members
448,967
Latest member
visheshkotha

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