Runtime error 1004 when copying pivot

jsamrai

New Member
Joined
Dec 11, 2010
Messages
1
Hi,
Wondering if someone could help. I keep getting a runtime 1004 error when I run the following code, even though it has been ok up until now. Last time, I thought it maybe that the file was too big, so reduced the size of the file, but this time it doesnt seem to be working. Can anyone suggest something?

Sub GeneratePages()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim iItem As Integer
Dim iNext As Integer
Dim str As String
Set pt = Sheet1.PivotTables(1)
Set pf = pt.PageFields("Owner")
For Each pf In pt.PageFields
For Each pi In pf.PivotItems
pt.PivotFields("Owner").CurrentPage = pi.Name

For iItem = 1 To pf.PivotItems.Count
If pf.PivotItems(iItem).Visible = True Then
iNext = iItem + 1
Exit For
End If
Next iItem
If iNext > pf.PivotItems.Count Then
iNext = 1
End If

ActiveSheet.Copy Before:=Sheets("Control")
str = pf.PivotItems(iNext).Name
pf.CurrentPage = pf.PivotItems(str).Name
Sheet1.Activate
Next
Next pf
End Sub

Thanks
 

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