VBA to Change Chart Data point colors?

junebug

Board Regular
Joined
Apr 4, 2003
Messages
110
Is there a way in a chart to change the color of a series point to red if the underlying data is <79%. I found code that changes all points in a series to one color but nothing would be conditional. Any ideas?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Thanks Mr. Poulsom. I elaborated on your code as I needed the line segment to change color not the data point marker if the data point was below 80% which is what is in cell R1. Below is what I came up with. You got me thinking in the right direction.
Code:
Sub ChangeDataPointColor()
'
Dim Pt As Point
    Dim Rng As Range
    Dim x As Integer
    Dim Y As Integer
    Dim MyColor
    Set Rng = ActiveSheet.Range("r4:r38")
    x = 1
    Y = 3
    
    
   Application.ScreenUpdating = False
     For Each Pt In ActiveSheet.ChartObjects("Chart 1").Chart.SeriesCollection(2).points
 ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(2).points(x).Select
    If Range("r" & Y).Value < Range("R1") Then
    MyColor = 3
    Else
    MyColor = 5
    End If
    
    With Selection.Border
        .ColorIndex = MyColor
        .Weight = xlThick
        .LineStyle = xlContinuous
    End With
 With Selection
        .MarkerBackgroundColorIndex = xlAutomatic
        .MarkerForegroundColorIndex = xlAutomatic
        .MarkerStyle = xlNone
        
        .MarkerSize = 5
        .Shadow = False
    End With
  x = x + 1
 
  Y = Y + 1
    Next Pt
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,211
Messages
6,177,162
Members
452,762
Latest member
manuha

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