I am just trying to chart a simple series, but I get some weird error when I try to label my axis. How can I label my x,y axis?
With ActiveSheet.ChartObjects.Add(Left:=10, Width:=875, Top:=75, Height:=425)
.Chart.SetSourceData Source:=ws.Range("A1:B" & rows)
.Chart.ChartType = xlLine
With ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Price"
End With
End With
The error is: Object variable or with block variable not set
This worked for me, try removing the with block within the other with:
ActiveSheet.Shapes.AddChart(Left:=10, Width:=875, Top:=75, Height:=425).Select
With ActiveChart
.SetSourceData Source:=ws.Range("A1:B" & rows)
.ChartType = xlLine
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Text = "Time"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Price"
End With
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.