Refinement of VBA

Access Beginner

Active Member
Joined
Nov 8, 2010
Messages
311
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I have the following code that severs the data connection to a couple of pivot tables on a couple of sheets. Is there a way to make the below code more compact/efficient?

Code:
Sheets("DebtSummaryIII").Select
    ActiveSheet.PivotTables("PivotTable2").SaveData = False
    ActiveWorkbook.ShowPivotTableFieldList = False
    
    Sheets("DebtSummaryII").Select
    ActiveSheet.PivotTables("PivotTable1").SaveData = False
    ActiveWorkbook.ShowPivotTableFieldList = False
    
    Sheets("DebtSummaryII").Select
    ActiveSheet.PivotTables("PivotTable2").SaveData = False
    ActiveWorkbook.ShowPivotTableFieldList = False
    
    Sheets("DebtPivotTable").Select
    ActiveSheet.PivotTables("DebtPivotTable").SaveData = False
    ActiveWorkbook.ShowPivotTableFieldList = False
    
    Sheets("DebtPivotTable").Select
    ActiveSheet.PivotTables("PivotTable1").SaveData = False
    ActiveWorkbook.ShowPivotTableFieldList = False

Using Excel 2013

Cheers
Haydn
 
You could try something like this:

Code:
    For i = 1 To Sheets("DebtSummaryIII").PivotTables.Count
        Sheets("DebtSummaryIII").PivotTables(i).SaveData = False
    Next i

And you only need this once: ActiveWorkbook.ShowPivotTableFieldList = False

HTH,
 
Upvote 0
Thanks Smitty,

Is there also a way to delete every pivot table in a Workbook, without the need to reference the sheets or pivot tables individually, which basically what my original code does ( deletes the data connection to every pivot table in the workbook).
 
Upvote 0

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