使用命名范围的多行 VBA
Multiple line using named ranges VBA
我正在尝试在图表上绘制多个命名范围。这些命名范围(例如命名为 Time_Series_1
)的形式为:
=INDIRECT(Ranges!$AJ)
这个参数 Ranges!$AJ
例如
="'Source Data'!"&ADDRESS(N3,(Comparisons!$G+5))&":"&ADDRESS(N3(Comparisons!$I+5))
我试图用来绘制这些范围的代码(我从一个开始,因为有一个不工作,所以不可能再有)是:
Sheets("Comparisons").Select
Sheet10.ChartObjects("Chart 2").Activate
Set Rng = range("Time_Series_1")
Set Date_Rng = range("Time_Series_Dates_1")
With ActiveChart
.SetSourceData Source:=Rng
.XValues = Date_Rng
End With
没用!图表保持空白。完全是空的。我没有更新什么?我没有激活什么?
谢谢
我无法测试你的模型,但试试这个:
Dim Chart_Sheet As Worksheet
Dim My_Chart As ChartObject
Dim Rng As Range
Dim Date_Rng As Range
Set Chart_Sheet = ThisWorkbook.Sheets("Comparisons")
Set My_Chart = Chart_Sheet.ChartObjects("Chart 2")
Set Rng = Range("Time_Series_1")
Set Date_Rng = Range("Time_Series_Dates_1")
With My_Chart.Chart
.SetSourceData Source:=Rng
.SeriesCollection(1).XValues = Date_Rng
End With
(我假设您的间接引用正常工作)
ActiveChart.SeriesCollection(1).XValues = Date_Rng
ActiveChart.SeriesCollection(1).Values = Rng
ActiveChart.Axes(xlCategory, xlPrimary).HasTitle = True
ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
ActiveChart.Axes(xlValue, xlPrimary).HasTitle = True
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Pounds"
ActiveChart.Axes(xlCategory).HasMajorGridlines = True
我正在尝试在图表上绘制多个命名范围。这些命名范围(例如命名为 Time_Series_1
)的形式为:
=INDIRECT(Ranges!$AJ)
这个参数 Ranges!$AJ
例如
="'Source Data'!"&ADDRESS(N3,(Comparisons!$G+5))&":"&ADDRESS(N3(Comparisons!$I+5))
我试图用来绘制这些范围的代码(我从一个开始,因为有一个不工作,所以不可能再有)是:
Sheets("Comparisons").Select
Sheet10.ChartObjects("Chart 2").Activate
Set Rng = range("Time_Series_1")
Set Date_Rng = range("Time_Series_Dates_1")
With ActiveChart
.SetSourceData Source:=Rng
.XValues = Date_Rng
End With
没用!图表保持空白。完全是空的。我没有更新什么?我没有激活什么?
谢谢
我无法测试你的模型,但试试这个:
Dim Chart_Sheet As Worksheet
Dim My_Chart As ChartObject
Dim Rng As Range
Dim Date_Rng As Range
Set Chart_Sheet = ThisWorkbook.Sheets("Comparisons")
Set My_Chart = Chart_Sheet.ChartObjects("Chart 2")
Set Rng = Range("Time_Series_1")
Set Date_Rng = Range("Time_Series_Dates_1")
With My_Chart.Chart
.SetSourceData Source:=Rng
.SeriesCollection(1).XValues = Date_Rng
End With
(我假设您的间接引用正常工作)
ActiveChart.SeriesCollection(1).XValues = Date_Rng
ActiveChart.SeriesCollection(1).Values = Rng
ActiveChart.Axes(xlCategory, xlPrimary).HasTitle = True
ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
ActiveChart.Axes(xlValue, xlPrimary).HasTitle = True
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Pounds"
ActiveChart.Axes(xlCategory).HasMajorGridlines = True