MACRO - Change Color of Bubble Chart Points Based on Values

mte498

New Member
Joined
Mar 23, 2019
Messages
5
Hello all,

I am trying to change the colors on an excel bubble chart based on specific values. I ran across the below video and it's ALMOST exactly what I need.

https://www.youtube.com/watch?v=nEOjcyGh1O0

I unfortunately have way more color combos than just the Red, Green, Blue that are in the video. My solution has been to randomly assign each data point a number that corresponds to a single RGB color combo. For example, RGB combo (1,1,1) is assigned the number 1, RGB combo (1,2,1) is assigned the number 2, etc. On the chart's data, instead of Red, Green, Blue, I will use excel's Random function to randomly assign a number that is within the range of values on the RGB combos.

What's the best way to use these numbers as the chart's color driver vs. the Red, Green, Blue?

Please let me know if anything is unclear. Confusing, I know.

Thank you!
Mike
 
This is it:

RtUgYsK.jpg


Code:
Sub BB()
Dim cht As Chart, ser As Series, r As Range, i%
ActiveSheet.ChartObjects("Chart 9").Activate       ' your chart name here
Set cht = ActiveChart
Set ser = cht.SeriesCollection(1)
ser.HasDataLabels = True
ser.DataLabels.Position = xlLabelPositionCenter
ser.Format.Fill.TwoColorGradient msoGradientFromCenter, 1
For i = ser.Format.Fill.GradientStops.Count To 3 Step -1
    ser.Format.Fill.GradientStops.Delete
Next
ser.Format.Fill.ForeColor.RGB = RGB(250, 250, 250)  ' white
Set r = [a78]                                       ' starting RGB cell
For i = 1 To ser.Points.Count
    ser.Points(i).Format.Fill.GradientStops.Insert r, 0.95
    With ser.DataLabels(i).Format.TextFrame2.TextRange
        .Characters.Text = r.Offset(1)
        .Font.Size = 11
    End With
    Set r = r.Offset(, 1)
Next
End Sub
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,216,246
Messages
6,129,700
Members
449,528
Latest member
Paula03

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