【问题标题】:keep secondary axis when changing chart filter更改图表过滤器时保留辅助轴
【发布时间】:2022-11-23 01:22:34
【问题描述】:

我一直在网上搜索,试图找到这个问题的答案,但无济于事,所以我求助于你。我有三个要显示的指标,但其中一个必须位于辅助轴上,每次我更改过滤器时辅助轴都会消失。

我想我可以使用 Worksheet_Change 事件,这样每当更改过滤器时,一行代码都会将该指标的 .AxisGroup 属性更改为 2。但我不确定如何捕捉 PivotItems.Visible 属性的变化。知道我会怎么做吗?或者,还有更好的方法?提前致谢。

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    好吧,我跑到堆栈溢出太快了。我自己想出了一个解决方法,所以我会把它贴在这里。不能保证它很漂亮!

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim pvtfield As PivotField
    Dim cnt As Long
    Dim i As Long
    Dim srs As Series
    Dim index As Long
    
    Worksheets("Brand Pivot Table").ChartObjects("Turn By Date").Activate
    cnt = ActiveChart.PivotLayout.PivotTable.PivotFields("Brand").PivotItems.Count
    For i = 1 To cnt
        If ActiveChart.PivotLayout.PivotTable.PivotFields("Brand").PivotItems(i).Visible = True Then
                index = 1
                For Each srs In ActiveChart.FullSeriesCollection
                    If InStr(srs.Name, "Turnover") <> 0 Then
                        ActiveChart.FullSeriesCollection(index).AxisGroup = 2
                    End If
                    index = index + 1
                Next srs
        End If
    Next i
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多