简体   繁体   English

宏以创建具有x轴值的图表excel

[英]macro to create chart with x axis values excel

im new to vba and this will create most of the chart i want but the x axis i would like to have a2:a133 be the x axis 我是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

i have tried adding the line 我尝试添加线

activeChart.Axes(xlCategory).Select
ActiveChart.SeriesCollection(1).XValues = _
"='CancNonPay Timing Report 09.26.'!$A$2:$A$133"

but that does not work. 但这不起作用。

Try this: 尝试这个:

ActiveChart.SetSourceData Source:=Union(Range("$A$1:$A$133"), Range("$S$1:$S$133")), PlotBy:=xlColumns

But also it looks like you're adding the chart on a new sheet, and both ranges in the line above will refer to this sheet, not the sheet that was active before inserting the new sheet. 而且看起来您正在将图表添加到新工作表上,并且上一行中的两个范围都将引用该工作表,而不是插入新工作表之前处于活动状态的工作表。

So maybe this: 所以也许这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM