Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15430

VS 2019 How to change color of Excel chart point?

$
0
0
I'm having trouble changing the color of a point in an Excel line chart.

The code snippet below loops through a range of dates checking each one to see if it is either the minimum or maximum date. If it is the minimum date, then the color of the point is set to red. If it is the maximum date, then the color of the point is set to green.

The intPointIndex allows the code to match the series points with the corresponding rows of data (dates).

Code:

srs = CType(myChart.SeriesCollection(1), Excel.Series)

For Each c In xlsWS.Range(xlsWS.Range("A1:A1"), xlsWS.Range("A1:A1").End(Excel.XlDirection.xlDown)).Cells
    intPointIndex += 1
    If IsDate(CType(c, Excel.Range).Value) Then
        Debug.WriteLine(CType(c, Excel.Range).Value)
        If CDate(CType(c, Excel.Range).Value).ToShortDateString = dtmMinDate.ToShortDateString Then
            pt = CType(srs.Points(intPointIndex - 1), Excel.Point)
            pt.MarkerBackgroundColor = RGB(255, 0, 0)    '...red (3)
            pt.MarkerForegroundColor = RGB(255, 0, 0)    '...red (3)
            pt.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle
        ElseIf CDate(CType(c, Excel.Range).Value).ToShortDateString = dtmMaxDate.ToShortDateString Then
            pt = CType(srs.Points(intPointIndex - 1), Excel.Point)
            pt.MarkerBackgroundColor = RGB(0, 255, 0)    '...green (4)
            pt.MarkerForegroundColor = RGB(0, 255, 0)    '...green (4)
            pt.MarkerStyle = Excel.XlMarkerStyle.xlMarkerStyleCircle
        End If
    End If
Next c

My coded compiles w/o error, but the point colors and markers don't change.

What am I doing wrong?

Viewing all articles
Browse latest Browse all 15430

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>