Finding all pivottables in a workbook using for each loop - 424 error

bachstrad

New Member
Joined
Jul 15, 2014
Messages
5
Hi all,

I'm new here, so forgive me if any formatting isn't right the first time!

I hope you guys can help me out with the following issue:

I'm trying to find all pivottables in a workbook using the following code. The goal is to instruct the found pivottables further on, but first I need to find them. The problem is the following code produces a 424-error message when the "for each" loop is started.

This is the code I used:
Code:
[FONT=courier new]Sub FindMyPTs()
Dim pt As PivotTable
Dim ptNames() As String
Dim ptName As String
Dim i As Integer

i = -1
For Each pt In PivotTables
i = i + 1
ReDim Preserve ptNames(i)
ptNames(i) = pt.Name
Next pt

For i = 0 To UBound(ptNames)
ptName = ptName & ptNames(i) & Chr(13)
Next i

MsgBox ptName
End Sub[/FONT]
What am I doing wrong? Can anyone please help me out!
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Welcome to MrExcel.

PivotTables is a member of the Worksheet object. So you need to loop around the worksheets and the pivot tables on them.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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