通过VBA在Excel中扩展数据透视表的特定部分和/或跳转到原始位置

时间:2022-09-15 20:22:20

I have a pivot table segmented by years, quarters and months. If I try to expand a quarter for 2015, however, the corresponding quarter in all other years are shown as well. How can I expand only one quarter for one year?
- https://superuser.com/questions/1049881/expanding-specific-sections-of-a-pivot-table-in-excel

我有一个按年,季度和月分段的数据透视表。但是,如果我试图在2015年扩大一个季度,那么所有其他年份的相应季度也会显示出来。我怎样才能在一年内只扩展一个季度? - https://superuser.com/questions/1049881/expanding-specific-sections-of-a-pivot-table-in-excel

This question got no answer there, but that wasn't a programming forum. I have a similar question. Is there a VBA solution?

这个问题没有得到答案,但这不是一个编程论坛。我有一个类似的问题。有VBA解决方案吗?

Alternatively, is there a VBA code that "catch" expansion clicks and then jump into the original cell on which plus was clicked?

或者,是否有一个VBA代码“捕获”扩展点击,然后跳转到单击加号的原始单元格?

通过VBA在Excel中扩展数据透视表的特定部分和/或跳转到原始位置

Sample file: http://ge.tt/2dNZ40n2

示例文件:http://ge.tt/2dNZ40n2

Sample code (I want this true just for 2016):

示例代码(我希望这只适用于2016年):

ActiveSheet.PivotTables(1).PivotFields("Month").PivotItems("3").ShowDetail = True

1 个解决方案

#1


0  

You can use something like this? This will be a good starting point for you, you'll have to create an IF THEN for each month

你可以用这样的东西吗?这将是一个很好的起点,你必须为每个月创建一个IF THEN

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

    If (ActiveSheet.PivotTables(1).PivotFields("Month").PivotItems("3").ShowDetail) Then
        ActiveSheet.PivotTables(1).PivotFields("Month").PivotItems("3").ShowDetail = False
        Sheets(2).Activate
        '''' Change filter options here? or have a cell selected?
    End If

End Sub

#1


0  

You can use something like this? This will be a good starting point for you, you'll have to create an IF THEN for each month

你可以用这样的东西吗?这将是一个很好的起点,你必须为每个月创建一个IF THEN

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

    If (ActiveSheet.PivotTables(1).PivotFields("Month").PivotItems("3").ShowDetail) Then
        ActiveSheet.PivotTables(1).PivotFields("Month").PivotItems("3").ShowDetail = False
        Sheets(2).Activate
        '''' Change filter options here? or have a cell selected?
    End If

End Sub