Change colors in bubble chart based on cell value

MPaul100

New Member
Joined
Aug 21, 2019
Messages
24
Hi,
I have a bubble chart that should change the bubble color based on a RGB code in a column. I have 4 criteria, therefore 4 color codes.
My chart is split in 4 frames, and the bubbles will change color based on criteria above.
The macro throws and error but it changes the colors properly with data unfiltered. The problem is that when I filter a column the bubble chart gets updated, but the colors are moving from their frames. I checked the codes and somehow the colors are modified, are not reflected as per my criterias.
Anyone has any idea on how to make it work with filtered data or some other way?
Thanks!
Code:
VBA Code:
Sub BB()
Dim cht As Chart, ser As Series, r As Range, i%
Sheets("Overview").ChartObjects("Graphique 3").Activate       ' your chart name here
Set cht = ActiveChart
Set ser = cht.SeriesCollection(1)
Set r = [I38]                                      ' starting RGB cell
'On Error Resume Next
For i = 1 To ser.Points.Count
    ser.Points(i).Format.Fill.ForeColor.RGB = r
    Set r = r.Offset(1)
Next
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I managed to find a solution myself
VBA Code:
Sub Tester()
    Dim s As Series, i As Long, X, y
    Set s = ThisWorkbook.Sheets("Overview").ChartObjects("Graphique 3").Chart.SeriesCollection(1)
    
    For i = 1 To s.Points.Count
        X = s.XValues(i)
        y = s.Values(i)
        If X < 0.8 And y < 600 Then
            s.Points(i).Format.Fill.ForeColor.RGB = vbRed
        End If
          If X < 0.8 And y >= 600 Then
            s.Points(i).Format.Fill.ForeColor.RGB = vbBlue
          End If
            If X >= 0.8 And y < 600 Then
              s.Points(i).Format.Fill.ForeColor.RGB = vbCyan
            End If
              If X >= 0.8 And y >= 600 Then
                s.Points(i).Format.Fill.ForeColor.RGB = vbGreen
              End If
    Next i
    With s.DataLabels.Font
            .Name = "Arial"
            .FontStyle = "Italic"
            .Size = 8
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = 1
            .Background = xlAutomatic
        End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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