我可以为一组数据创建图表。我不想在图表中包含第179行的数据,但我需要将其保留在工作表内。
如何通过修改以下代码来修改我的图表以将第178行(标题)和第180行:182行作为数据系列?
ActiveSheet.Shapes.AddChart.Select
With ActiveChart
.SetSourceData Source:=Range("'eod summary'!$B$178:$H$182")
.ChartType = xlAreaStacked
.Axes(xlCategory).CategoryType = xlCategoryScale
End With
答案 0 :(得分:2)
您的范围参考是硬编码的;如果始终为true,则构建一个Union引用以用于SetSourceData。
ActiveSheet.Shapes.AddChart.Select
With ActiveChart
'shorthand method
.SetSourceData Source:=Range("'eod summary'!$B$178:$H$178,'eod summary'!$B$180:$H$182")
'Union(..., ...) method; more verbose but also more explanatory
'.SetSourceData Source:=Union(Range("'eod summary'!$B$178:$H$178"), _
Range("'eod summary'!$B$180:$H$182"))
.ChartType = xlAreaStacked
.Axes(xlCategory).CategoryType = xlCategoryScale
End With
答案 1 :(得分:0)
可以使用FullSeriesCollection属性来定义标题:
ActiveSheet.Shapes.AddChart.Select
With ActiveChart
.SetSourceData Source:=Range("B180:H182")
.FullSeriesCollection(1).XValues = "='eod summary'!$B$178:$H$178"
.ChartType = xlAreaStacked
.Axes(xlCategory).CategoryType = xlCategoryScale
End With