我是vba的新手,这将创建我想要的大部分图表,但x轴我希望有a2:a133是x轴
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("$S$1:$S$133")
ActiveChart.ChartType = xlLine
With ActiveChart.Parent
.Height = 500
.Width = 1050
.Top = 1
.Left = 1
End With
我尝试添加行
activeChart.Axes(xlCategory).Select
ActiveChart.SeriesCollection(1).XValues = _
"='CancNonPay Timing Report 09.26.'!$A$2:$A$133"
但这不起作用。
答案 0 :(得分:0)
试试这个:
ActiveChart.SetSourceData Source:=Union(Range("$A$1:$A$133"), Range("$S$1:$S$133")), PlotBy:=xlColumns
但是,您似乎还要在新工作表上添加图表,上面一行中的两个范围都将引用此工作表,而不是插入新工作表之前处于活动状态的工作表。
所以也许这个:
ActiveChart.SetSourceData Source:=Union(Range("'CancNonPay Timing Report 09.26.'!$A$1:$A$133"), _
Range("'CancNonPay Timing Report 09.26.'!$S$1:$S$133")), PlotBy:=xlColumns