When I change a selection in a pivot table page item, the table’s length and/or width changes based on the underlying data.
Below the last (Grand Total) row, I want to insert two rows of formulas. The location of these formulas must also be dynamic.
The worksheet_calculate event looks like this:
Private Sub Worksheet_Calculate()
……Dim myLastCell As String
……If PivotPageItemSelectionWasChanged Then
………Application.Calculation = xlManual
………Remove_Formulas ‘remove formulas from old location (if not removed by pivot)
………Insert_Formulas ‘insert formulas at new location
……..Application.Calculation = xlCalculationAutomatic
……End If
……GotoLastCell
……myLastCell = ActiveCell.Address(ReferenceStyle:=xlA1)
……ActiveSheet.PageSetup.PrintArea = “$A$1:” & myLastCell
……Application.StatusBar = “Lastcell: ” & myLastCell
End Sub
I can’t figure out how to trap a change in the pivot so I can set the boolean PivotPageItemSelectionWasChanged var to TRUE.
It would also be preferable if I could remove the old formulas before the pivot was changed.
Anybody know how?