VBA从阵列中的所有图表中添加或删除“预算”系列

时间:2019-02-25 18:45:06

标签: excel vba

我在这方面还很陌生,但是我试图做出一个切换开关,该开关将添加或删除MyArray中所有图表中的“预算”系列。该子程序本身可以正常工作,但是它调用的私有子程序似乎没有作用。需要考虑的一件事是,“预算系列”并不总是被称为“预算”,例如“预算毛利”等任何帮助都是极好的。谢谢大家

`Sub ToggleBudget()

If Sheets("Dashboard").Shapes("Button 6").TextFrame.Characters.Text = "Add Budget" Then
    Sheets("Dashboard").Shapes("Button 6").TextFrame.Characters.Text = "Remove Budget"
    Call Budget_On
ElseIf Sheets("Dashboard").Shapes("Button 6").TextFrame.Characters.Text = "Remove Budget" Then
    Sheets("Dashboard").Shapes("Button 6").TextFrame.Characters.Text = "Add Budget"
    Call Budget_Off
End If
Sheets("Dashboard").Select
Cells(1, 1).Select

End Sub


Private Sub Budget_On()

Dim MyArray As Variant
MyArray = Array("Company KPI", "People KPI", "Sales & Mkg KPI", "Service & Operations KPI", "Seasonality & Industry Comp")
        For Each ChartObject In MyArray
                For Each SeriesCollection In Charts
                    For Each Series In SeriesCollection
                        If Series.Name Like "*Budget*" Then
                        Chart.SeriesCollection(Series.Name).IsFiltered = True
                        End If
                    Next Series
               Next SeriesCollection
    Next ChartObject

End Sub


Private Sub Budget_Off()

Dim MyArray As Variant
MyArray = Array("Company KPI", "People KPI", "Sales & Mkg KPI", "Service & Operations KPI", "Seasonality & Industry Comp")
        For Each ChartObject In MyArray
                For Each SeriesCollection In Charts
                    For Each Series In SeriesCollection
                        If Series.Name Like "*Budget*" Then
                        Chart.SeriesCollection(Series.Name).IsFiltered = False
                        End If
                    Next Series
               Next SeriesCollection
    Next ChartObject

End Sub`

0 个答案:

没有答案