Asking for some help with this code found thru google that I'm attempting to use on any pivot table. The goal is to be able to select any row item in a pivot table and then have a macro 'drilldown' to the last column for that row, similar to clicking all the '+' signs to expand that row item.
I'm currently getting a Run-Time error 438 at the 'Set pi = pt.ActiveCell.PivotCell.PivotItem' line. I believe the error is telling me that ActiveCell is not a valid reference in a pivot table, but I'm not sure how to correct the problem.
I can see that 'pt' is the pivot table name and 'ActiveCell' is the pivot table item name, but when I put the two together I'm getting the same error 438 at the 'msgBox pt.ActiveCell' line as I am at the 'Set pi = pt.ActiveCell.PivotCell.PivotItem' line.
TIA,
Don
I'm currently getting a Run-Time error 438 at the 'Set pi = pt.ActiveCell.PivotCell.PivotItem' line. I believe the error is telling me that ActiveCell is not a valid reference in a pivot table, but I'm not sure how to correct the problem.
I can see that 'pt' is the pivot table name and 'ActiveCell' is the pivot table item name, but when I put the two together I'm getting the same error 438 at the 'msgBox pt.ActiveCell' line as I am at the 'Set pi = pt.ActiveCell.PivotCell.PivotItem' line.
TIA,
Don
VBA Code:
Option Explicit
Sub DrillDownToSpecificField()
Dim pt As PivotTable
Dim pi As PivotItem
Dim pl As PivotLine
Set pt = ActiveCell.PivotTable
MsgBox pt
MsgBox ActiveCell
' MsgBox pt.ActiveCell
Set pi = pt.ActiveCell.PivotCell.PivotItem '<<< Run-time error 438 here
Set pl = pt.ActiveCell.PivotCell.PivotLine
pt.DrillDown pi, pl
End Sub