PDA

View Full Version : Vba data for chart



Bapek3
08-27-2018, 05:58 AM
Hi

Please service where i am making a mistake

I need to select the data for the chart
I do it this but it does not work



Sub data_chart

Dim chart as long

chart = range("a5").end(xlToRight).offset(0, 1).select

ActiveSheet.chartObject("chart 1").activate
Active.Chart.ChartArea.select
Activated.Chart.SetSourceData Source:=Range("a1" & ":" & "chart")

End sub

Thank you for your advice

offthelip
08-27-2018, 10:48 AM
try this:

With Worksheets("sheet1")
lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
Row = 1
End With
Worksheets("Sheet1").ChartObjects("chart 1").Chart.SetSourceData Source:=Sheets("Sheet1").Range(Cells(Row, 1), Cells(Row, lastcol)), PlotBy:=xlRows
Worksheets("Sheet1").ChartObjects("chart 1").Chart.ChartType = xlLine

Bapek3
08-27-2018, 11:15 AM
Unfortunately, this does not work. I need to find tle last full column and pit it in the graph data.

The chart data will start with A1 and end up with F7, G7 or H7 and so on.
The tabule will look:

Bapek3
08-27-2018, 11:18 AM
And graph will look:

p45cal
08-27-2018, 02:32 PM
Sub data_chart()
Dim chart As Long
chart = Range("a5").End(xlToRight).Column
ActiveSheet.ChartObjects("Chart 1").chart.SetSourceData Source:=Range(Cells(1, 1), Cells(7, chart))
End Sub
?