我试图将图表嵌入到我已设置为工作表的变量中。 但它无法正常运行。我不确定该陈述是否正确。
Public DataSheet As Worksheet
Public Graph As Chart
Public Cat_3, Cat_4, Cat_5 As Range
Set DataSheet = Worksheets("DataSheets")
Set Cat_3 = DataSheet.Range("c2:c16")
Set Graph = Charts.Add
Graph.SeriesCollection.NewSeries
Graph.SeriesCollection(1).Values = Cat_3
Set Graph = Graph.Location(Where:=xlLocationAsObject, Name:=DataSheet)
我上次收到错误,有什么建议吗?
谢谢!
答案 0 :(得分:1)
使用
Graph.Location Where:=xlLocationAsObject, Name:=DataSheet.Name
此外,您可能希望使用更强大的语法,如下所示:
Set Graph = Charts.Add
With Graph
.SeriesCollection.NewSeries
.SeriesCollection(1).Values = Cat_3
.Location Where:=xlLocationAsObject, Name:=DataSheet.Name
End With