Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of data series in excel xyscatter chart

Tags:

graph

excel

vba

I'm trying to change the color of the data points in an excel chart but everything im trying unsuccessful.

This is one method I tried, yet the points still appear blue:

With Chrt
.ChartType = xlXYScatter
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
    .SeriesCollection.NewSeries

                .SeriesCollection(1).Name = "=""Top Platen"""
                .SeriesCollection(1).Values = yaxis
                .SeriesCollection(1).XValues = xaxis

                ActiveChart.SeriesCollection(1).Select
                 With Selection.Format.Fill
                    .Visible = msoTrue
                    .ForeColor.RGB = RGB(255, 0, 0)
                    .Transparency = 0
                    .Solid
                End With

Here's another method I tried and still the data points appear blue:

With Chrt
.ChartType = xlXYScatter
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
    .SeriesCollection.NewSeries

                .SeriesCollection(1).Name = "=""Top Platen"""
                .SeriesCollection(1).Values = yaxis
                .SeriesCollection(1).XValues = xaxis
                .SeriesCollection(1).Interior.Color = RGB(255,0,0)

This is only one segment of my code, I can supply additional areas if necessary. Any help would be greatly appreciated.

like image 620
Dimitri M Avatar asked Oct 12 '25 17:10

Dimitri M


1 Answers

I believe the problem is with the nested With blocks getting confused. Here is one way to solve it and still use nested With block:

With Chrt
    .ChartType = xlXYScatter

    Do Until .SeriesCollection.Count = 0
        .SeriesCollection(1).Delete
    Loop

    .SeriesCollection.NewSeries

    With .SeriesCollection(1)
        .Name = "=""Top Platen"""
        .Values = yaxis
        .XValues = xaxis
        .Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
    End With
End With

Here is Microsoft's documentation link that talks about fully qualified nested With blocks.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!