Create chart line with data only in y-axis

102 Views Asked by At

i don't know if is possible to create a chart line with y-axis values only, the y-axis values contain the cells A1+B1+C1+D1. and create a loop to make series until to last row.

i'm need create this chart in the image, when i create the line only insert the values in y-series and by default the horizontal axis labels put the numbers from 1 to 4

I mean if it is possible i can make this infinity times acording to the data density (last row) to create lines per each row in my data. i need make it please!!! is to much work insert each per each, i have 3650 rows :(

I have a macro for a chart with x-axis and y-axis but, really i don't know how to do when x-axis no have data and y-axis has 2 or more cells.

 Sub RefreshRange_series()

Dim LastRow As Long
Dim Rng1 As Range
Dim n As Long
Dim c As Range

With Sheets("DATA GRAPH")
    LastRow = .Range("B" & .Rows.Count).End(xlUp).Row
    Set Rng1 = .Range("AD3:AD" & LastRow & ", AG3:AG" & LastRow)
End With

For Each c In Rng1.Cells
       'is the row visible? skip if not
        If Not c.EntireRow.Hidden Then
        n = n + 1
With ActiveChart
    .SetSourceData Source:=Rng1
End With
       End If
  Next c
End Sub
1

There are 1 best solutions below

0
On

Try,

Sub RefreshRange_series()
    
    Dim LastRow As Long
    Dim rngDB As Range, rng As Range
    Dim n As Long
    Dim c As Range
    Dim objChart As ChartObject
    Dim Cht As Chart
    Dim Ws As Worksheet
    Dim Srs As Series
    
    Set Ws = Sheets("DATA GRAPH")
    
    With Ws
        LastRow = .Range("B" & .Rows.Count).End(xlUp).Row
        'Set Rng1 = .Range("AD3:AD" & LastRow & ", AG3:AG" & LastRow)
        Set rngDB = .Range("AD3:AD" & LastRow)
        
        Set objChart = .ChartObjects(1)
        Set Cht = objChart.Chart
        With Cht
            .ChartType = xlXYScatter '<~~ has Makers
            '.ChartType = xlXYScatterLinesNoMarkers '<~~ Line
            'Delete all previous series.
            For Each Srs In .SeriesCollection
                Srs.Delete
            Next Srs
            For Each rng In rngDB
                Set Srs = .SeriesCollection.NewSeries 'add new series
                With Srs
                    .XValues = Array(1, 2, 3, 4) ' x values
                    .Values = rng.Resize(1, 4) 'y values
'                    .MarkerStyle = xlMarkerStyleCircle '<~~set marker style and size, color
'                    .MarkerSize = 10
'                    .MarkerBackgroundColor = vbBlue
'                    .MarkerForegroundColor = vbRed
                End With
            Next rng
        End With
    End With

End Sub