Pivot table macro error with OLAP

kwhite100

Board Regular
Joined
Aug 18, 2010
Messages
91
Hello everyone,

I have been struggling trying to handle an error that I am receiving. I am using a tool on the internet to analyze some data and am getting a pivot table as a result of the analyzer. I export this pivot table to an excel sheet and my goal is to run a macro to select various elements within the filters of the pivot table. The excel sheet connects to an external data source, which may be why I am receiving the error, "Run Time error '1004': Unable to get the PivotFields property of the WORKSHEET class."

Please note that I am using OLAP to connect to an existing data source. I think this may be what is causing me problems.

Here is my code

Code:
[FONT=Calibri][SIZE=3]Sub Armeda_Pivot()[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]cntItem = 0[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Dim arrVisibleItems[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]arrVisibleItems = Array("BERRYPET8144001") ' Fill in the items you want to display in pivot[/SIZE][/FONT]
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
[FONT=Calibri][SIZE=3]For Each pvtRowItem In ActiveSheet.PivotTables("PivotTable1").PivotFields("Project").PivotItems[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' update the pivot name and row field name[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]pvtRowItem.Visible = True[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]cntItem = cntItem + 1[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Next pvtRowItem[/SIZE][/FONT]
<o:p></o:p>
<o:p></o:p>
[FONT=Calibri][SIZE=3]If cntItem < UBound(arrVisibleItems) Then[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]MsgBox "array has more items than listed in pivot"[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Exit Sub[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]End If[/SIZE][/FONT]
<o:p></o:p>
[FONT=Calibri][SIZE=3]For Each pvtRowItem In ActiveSheet.PivotTables("PivotTable1").PivotFields("Project").PivotItems[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]If Not (arrSearch(pvtRowItem.Value, arrVisibleItems)) Then[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]pvtRowItem.Visible = False[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]End If[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Next pvtRowItem[/SIZE][/FONT]
<o:p></o:p>
[FONT=Calibri][SIZE=3]End Sub[/SIZE][/FONT]
<o:p></o:p>
[FONT=Calibri][SIZE=3]Public Function arrSearch(strSearch As String, arrStrToBeSearched As Variant) As Boolean[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]For i = 0 To UBound(arrStrToBeSearched)[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]If strSearch = arrStrToBeSearched(i) Then[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]arrSearch = True[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Exit Function[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]End If[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Next i[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]arrSearch = False[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]End Function[/SIZE][/FONT]
<o:p></o:p>
[FONT=Calibri][SIZE=3]End Function[/SIZE][/FONT]

Thanks!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi kwhite100,

Are you filtering for one item or multiple items?
What area of the report are you filtering (Pagefield/Rowfield/ColumnField or DataField)?
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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