-1

Is there a way to access the color of a new series line in a scatter chart that is created dynamically using VBA? I want to take the color of the line of the new series and put it as the background of a cell near where the data is for the new series.

I can't seem to find how to access the color of a series when it is created.

braX
  • 11,506
  • 5
  • 20
  • 33
cspencer
  • 3
  • 1
  • If you record a macro while changing the color, that will show you which properties you need to look at for the new series. – Tim Williams Sep 16 '22 at 19:25
  • I've tried that, but it doesn't show the property for this when I do it manually while recording. Manually, you have to go into the series properties and open the color window to find the RGB codes, and then assign it to the cell that way. The recording doesn't know that I am getting the RGB codes from the series in the chart. – cspencer Oct 03 '22 at 21:03

1 Answers1

0

If I record a macro while setting the color I get:

Sub Macro1()
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.FullSeriesCollection(1).Select
    With Selection.Format.Line
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 0, 0)
        .Transparency = 0
    End With
    Range("I29").Select
End Sub

So to read the value you can do something like:

Sub Tester()
    Dim cht As Chart
    Set cht = ActiveSheet.ChartObjects(1).Chart
    Debug.Print cht.SeriesCollection(1).Format.Line.ForeColor.RGB
End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Sorry for the late comment, but this worked. Thank you, I really appreciate it!! - Have a blessed day. – cspencer Oct 20 '22 at 14:12