Home > Software engineering >  Remove the marker from scatterplot chart in VBA
Remove the marker from scatterplot chart in VBA

Time:03-22

I would Like to remove the marker from my scatter plot in VBA but I cant figure out how to do this. I already googled for a while and also used the macro recorder, but none of the suggestions seem to work (Also included my trial solutions in the code).

Sub RekFiguur()

Mod_berekening.clearShape "UGT - moment", "B7:T19"

Dim wb As Workbook: Set wb = ThisWorkbook
Dim sht As Worksheet: Set sht = wb.Sheets("UGT - moment")
Dim sh As Shape

Dim chartObj As ChartObject
Dim chartSheet As Chart
Dim activeRow As Integer
Set chartObj = sht.ChartObjects.Add(Top:=80, Left:=20, Width:=240, Height:=150)

With chartObj.Chart
    .ChartType = xlXYScatterLines
    .HasLegend = False
    .Parent.Name = "UGT-rek"
    
    'Draw strain for concrete
    .SeriesCollection.NewSeries
    With .SeriesCollection(1)
        .Name = "UGT-beton-rek"
        
        .xValues = sht.Range("$AA$9:$AA$15")
        .Values = sht.Range("$AE$9:$AE$15")
        '.MarkerStyle = xlMarkerStyleNone            'No response
        '.MarkerStyle = -4142                       'No response
        '.Format.Fill.Visible = msoFalse             'Removes only fill
        '.Format.Line.Visible = msoFalse            'Does remove the marker but cant edit line anymore
        .Format.Line.Weight = 1
        .Format.Line.DashStyle = msoLineSolid
        .Format.Line.ForeColor.RGB = RGB(0, 0, 0)
    End With
    
    .HasTitle = True
    .HasTitle = False

'Some more irrelevant code for the chart I left out

end with

See below the result, sadly with markers. Weird thing, is the straight lines are made with an exact copy of the code, but have only two datapoints, and those markers are removed nicely, I have no clue on this one..

enter image description here

Thanks in advance. Please be a little kind, if you need more information I will happily clarify

See the code above. I also tried the solution from https://stackoverflow.com/questions/45429026/setting-line-on-xy-scatter-without-having-a-marker-line But that did not help me either

CodePudding user response:

Change

.ChartType = xlXYScatterLines

to

.ChartType = xlXYScatterLinesNoMarkers
  • Related