VBA to Drill Down in a PivotChart - Error 91

pjmorris

Well-known Member
Joined
Aug 2, 2012
Messages
2,171
Office Version
  1. 365
Platform
  1. Windows
HI,

As part of a project I want to use VBA to drill down in a pivotchart. I've referred to the documentation here: MicrosoftDocs - Pivotchart Drilldown and the code snippet provided there:

VBA Code:
ActiveChart.PivotLayout.PivotTable.DrillDown ActiveChart.PivotLayout.PivotTable _
      .PivotFields("[Customer].[Customer Geography].[Country]").PivotItems( _
      "[Customer].[Customer Geography].[Country].&[Australia]"), ActiveChart. _
      PivotLayout.PivotTable.PivotRowAxis.PivotLines(1)

is very similar to the code I've recorded:

VBA Code:
Sub Macro6()
'
' Macro6 Macro
'
    ActiveSheet.ChartObjects("chtDataEntry2").Activate
    ActiveChart.Axes(xlCategory).Select
    ActiveChart.PivotLayout.PivotTable.DrillDown ActiveChart.PivotLayout.PivotTable _
        .PivotFields("[qryCategories].[Category].[Category]").PivotItems( _
        "[qryCategories].[Category].[Category].&[Fuel/Oil]"), ActiveChart.PivotLayout.PivotTable. _
        PivotRowAxis.PivotLines(8)
End Sub

But when I run Macro6 i get an Error 91 - 'Object Variable or With Block Variable not set'. I know the correct chart has been activated because the error only occurs on the ActiveChart.PivotLayout.PivotTable.DrillDown line.

Any ideas gratefully received.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
for avoidance of duplication - please note that I've posted the same question on StackOverflow.com here
 
Upvote 0

Forum statistics

Threads
1,215,756
Messages
6,126,692
Members
449,330
Latest member
ThatGuyCap

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top