gpt4 book ai didi

VBA创建图表并删除系列

转载 作者:行者123 更新时间:2023-12-02 07:37:19 27 4
gpt4 key购买 nike

我能够为一组数据创建图表。我不想将第 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

最佳答案

您的范围引用是硬编码的;如果这始终为真,则构建 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

关于VBA创建图表并删除系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37579023/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com