VBA Excel图表系列集锦 [英] VBA Excel Chart SeriesCollection
问题描述
我在最后几个小时内遇到错误,正在努力工作。
我想为每个工作表绘制相同的范围的代码。
当我添加一个系列集合失败。
我从一个录制的宏修改了代码,这完美地工作。
这是有问题的代码:
Sub plot()
$错误是:
Dim wb As Excel.Workbook
Set wb = ThisWorkbook
Dim ws as Worksheet
Dim name As String
Dim plot As Excel.Shape
对于每个ws在wb .Worksheets
name = ws.name
设置plot = ws.Shapes.AddChart
plot.Chart.ChartType = xlXYScatterLines'until这里它完美地工作
plot.Chart.SeriesCollection 1).name ==something'在这行我得到错误
下一个
结束子
运行时错误'1004':
应用程序定义或对象定义错误
并且帮助说,这是一个错误从excel,而不是VBA,所以它不关心... :)
任何帮助将非常感激。
Cheers!解决方案我想你需要添加
plot.Chart.SetSourceData Range(A1,D4)
$ b b
Dim wb As Excel.Workbook
设置wb = ThisWorkbook
Dim ws作为工作表
Dim名称作为字符串
Dim plot As Excel.Shape
For ws In wb.Worksheets
name = ws.name
设置plot = ws.Shapes.AddChart
plot.Chart.ChartType = xlXYScatterLines'直到这里它完美地工作
plot.Chart.SetSourceData Range(A1,D4)
plot.Chart.SeriesCollection(1).name ==something'这行我得到错误
Next
End Sub
I'm struggling for the last couple of hours with an error. I want to make a code that plots the same range for each sheet. When I add a series collection it fails. I have modified the code from a recorded macro, which works perfectly. This is the code in question:
Sub plot()
Dim wb As Excel.Workbook
Set wb = ThisWorkbook
Dim ws As Worksheet
Dim name As String
Dim plot As Excel.Shape
For Each ws In wb.Worksheets
name = ws.name
Set plot = ws.Shapes.AddChart
plot.Chart.ChartType = xlXYScatterLines'until here it works perfectly
plot.Chart.SeriesCollection(1).name = "=""something"""' on this line I get the error
Next
End Sub
And the error is:
Run - time error '1004':
Application-defined or object-defined error
And the help says that is an error from excel, not VBA, so it doesnt care... :) Any help will be much appreciated. Cheers!
I think you need to add
plot.Chart.SetSourceData Range("A1", "D4")
just below the line that works perfectly, so you end up with this
Sub plot()
Dim wb As Excel.Workbook
Set wb = ThisWorkbook
Dim ws As Worksheet
Dim name As String
Dim plot As Excel.Shape
For Each ws In wb.Worksheets
name = ws.name
Set plot = ws.Shapes.AddChart
plot.Chart.ChartType = xlXYScatterLines 'until here it works perfectly
plot.Chart.SetSourceData Range("A1", "D4")
plot.Chart.SeriesCollection(1).name = "=""something""" ' on this line I get the error
Next
End Sub
这篇关于VBA Excel图表系列集锦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!