VBA excel pivot field removal error and Grandtotal disfunction

David_Neal

New Member
Joined
Mar 15, 2011
Messages
3
In making a macro to manipulate an excel pivot for final formatting, I've run into 2 strange problems.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
1st, while removing existing pivot fields from the pivot, the macro generates an error 1004 code for 2 lines alone. The rest work just fine. Since I pulled this from a recorded macro, and the formatting/content is the same as the other lines I can't see what's wrong. Perhaps a line length limitation? Code is below, with problem area bolded.<o:p></o:p>
ActiveSheet.PivotTables("ross pivot").PivotFields("Beg Qtr Mth 1 Qty (K#)"). _
Orientation = xlHidden
ActiveSheet.PivotTables("ross pivot").PivotFields("Beg Qtr Mth 2 Qty (K#)"). _
Orientation = xlHidden
ActiveSheet.PivotTables("ross pivot").PivotFields("Beg Qtr Mth 3 Qty (K#)"). _
Orientation = xlHidden
ActiveSheet.PivotTables("ross pivot").PivotFields( _
"Beg Qtr Qty before Delq (K#)").Orientation = xlHidden
ActiveSheet.PivotTables("ross pivot").PivotFields("Beg Qtr Delq Qty (K#)"). _
Orientation = xlHidden
ActiveSheet.PivotTables("ross pivot").PivotFields("Beg Qtr Qty with Delq (K#)") _
.Orientation = xlHidden<o:p></o:p>

The 2nd problem is that the following instruction to disable Grand Total in the pivot is ignored altogether.<o:p></o:p>
ActiveSheet.PivotTables("ross pivot").RowGrand = False<o:p></o:p>
<o:p></o:p>
Again, this was copied from a recorded macro so not sure how I'm going astray. Any suggestions on fixing, or as to cause, would be very much appreciated.<o:p></o:p>
<o:p></o:p>
David
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Well, I'm answering my own questions, based on a peer's input.
Whenever you record a macro which hides a calculated field in a pivot, the code recorded doesn’t work. You could argue whether it’s recording bad code, or failing to execute good code, but the net result is the same. An alternative way (that works) of asking Excel to perform the same operation :
ActiveSheet.PivotTables("ross pivot").DataPivotField.PivotItems("Beg Qtr Qty before Delq (K#)").Visible = False

For the 2nd problem, it seems that excel's recording mechanism erroneously records ColumnGrand as RowGrand. Isn't that odd!?

David S
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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