本文介绍了使用Excel Macros / vba打开/关闭图表系列的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Excel中制作折线图(图表),将多个数据系列绘制到同一张图表上。

I am making a line graph (chart) in Excel with several data series being plotted onto the same chart.

我需要创建一个宏/ VBA解决方案,可以通过按一个按钮(或勾选框等)来打开/关闭这些系列的可见性。

I need to create a macro/VBA solution that can turn the visibilty of these series on/off via the pressing of a button (or tick box etc)

类似于此图片(通常通过excel菜单系统完成)

Similar to this picture (manually done through the excel menu system)

我尝试查看所有成员变量/方法

I have tried to look through all the member vars/methods on

但运气还不太好。

我尝试过像

Charts("Chart1").SeriesCollection(1)

Worksheets("Graphical Data").ChartObjects(1)

,但是我既无法获取图表对象(我的下标超出范围错误),也无法找到允许我打开/关闭各个系列的可见性的任何方法。

but I can neither get the chart object ( I get a subscript out of range error) nor able to find any method that would allow me to turn on/off the visibility of individual series.

有什么想法吗?

推荐答案

每当我不知道如何要执行类似的操作,请打开宏记录器。

Whenever I don't know how to do something like this, I turn on the macro recorder.

我有一个包含四个系列的图表,并且使用Excel 2013中的过滤器功能隐藏和显示第二个系列,而宏记录器正在运行。

I had a chart with four series, and I used the filter function in Excel 2013 to hide and show the second series, while the macro recorder was running.

以下是相关代码:

ActiveChart.FullSeriesCollection(2).IsFiltered = True
' series 2 is now hidden
ActiveChart.FullSeriesCollection(2).IsFiltered = False
' series 2 is now visible

系列类型(行或列)无关紧要,这对任何一个都适用。

The series type (line or column) does not matter, this works for any of them.

这篇关于使用Excel Macros / vba打开/关闭图表系列的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:33