【发布时间】:2016-01-21 12:50:20
【问题描述】:
我必须创建近 200 个时间序列图表。所以我尝试编写一个宏来完成我需要做的大部分工作。
我以这样的时间序列生成名称为例:
Name:= AKB_ExampleA
名称指的是我用这个公式声明的动态范围:
=OFFSET('sheet1'!$C$7:$C$137;0;0;COUNT('sheet1'!$C$7:$C$206))
现在到我编写的宏:
Sub graphik_erstellen()
Call graphik1("AKB")
End Sub
Sub graphik(Name As String)
'
Dim Ch As Chart
Dim RngToCover As Range
Set Ch = charts.Add
Set Ch = Ch.Location(Where:=xlLocationAsObject, Name:="Charts")
With Ch
.ChartType = xlLine
.SetSourceData Source:=Range(Name & "_ExampleA")
.SeriesCollection(1).XValues = Range("Datum_Volumen")
.SeriesCollection(1).Name = "SERIES1"
.FullSeriesCollection(1).Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(192, 0, 0)
.Transparency = 0
End With
.HasTitle = True
.ChartTitle.Text = Name & ", Volumen (nach Korrektur)"
.HasLegend = True
.Legend.Position = xlLegendPositionBottom
.Legend.Select
Selection.Format.TextFrame2.TextRange.Font.Size = 11
Selection.Format.TextFrame2.TextRange.Font.Bold = msoTrue
With .Parent
.top = 100
.left = 100
.height = 287.149606299
.width = 543.685039370078
.Name = Name & "_chart"
End With
End With
End Sub
我的问题是,如果我这样做,则不会真正考虑动态范围。它采用名称的范围(即 $C$7:$C$137),但它应该引用名称本身(以便动态)。
因此,如果我单击图表查看系列,系列值将声明为:='sheet1'!$C$7:$C$137 而不是 ='sheet1'!ExampleA。
如果有人能帮助我,我会非常非常感激。 最好的 埃利奥
【问题讨论】:
-
欢迎来到 StackOverFlow。你真的应该使用
Range设置你的Range。只是为了确认您希望捕获到图表中的工作表上的范围是多少? -
添加了段落并修正了一些语法
-
感谢你们到目前为止的cmets。 @Jean-Pierre Oosthuizen 所以我的范围需要是动态的。起价为 7 加元,目前为 137 加元。每个月都会添加新数据,因此图表应该会自动调整。
-
我看到你使用的是 Office 2010 还是 360
FullSeriesCollection -
这是 Office 360