Excel VBA Code needed to connect 3 slicers to pivot table without right clicking and selecting report connections for each slicer

daustin51

New Member
Joined
Oct 22, 2021
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I recorded a macro to see if there was a way after I inserted 3 slicers, to select report connections for each of the slicers to select pivot table without having to
right click and select report connections for each slicer.

This is the below macro code from the recorder:

Sub Macro3()
'
' Macro3 Macro
'

'slicer 1
ActiveSheet.Shapes.Range(Array("Team Member Name")).Select
ActiveWorkbook.SlicerCaches("Slicer_Team_Member_Name").PivotTables. _
AddPivotTable (ActiveSheet.PivotTables("PivotTable2"))
'slicer 2
ActiveSheet.Shapes.Range(Array("Opportunity Owner Name")).Select
ActiveWorkbook.SlicerCaches("Slicer_Opportunity_Owner_Name").PivotTables. _
AddPivotTable (ActiveSheet.PivotTables("PivotTable2"))
'slicer 3
ActiveSheet.Shapes.Range(Array("Account Record Type")).Select
ActiveWorkbook.SlicerCaches("Slicer_Account_Record_Type").PivotTables. _
AddPivotTable (ActiveSheet.PivotTables("PivotTable2"))
End Sub

when I run the code, it gives me the following error


1665878707323.png


and error in code is shown below

1665878770407.png



Any help provided would be great and been searching for the last few hours and nothing. Thanks as always.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

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