VBA pivotTable.rowField question

bmurn

New Member
Joined
Jun 14, 2011
Messages
7
ActiveSheet.PivotTables("Rank Hospital Pivot").PivotFields("GroupInd").CurrentPage = Range("SelectGroupInd").Value

So I have drop down boxes on the front page of my excel sheet and want to filter pivot tables that the data is read from based on these drop down boxes.

All the drop downs which reference page fields in the pivot table are easily switched, it is the row fields which are giving me trouble.

Based on the drop down, only one rowfield value can be selected so I need to change the pivot table from showing all of the values in the row field at once to showing just one of the values in the row field. I was thinking I could find a way in VBA to hide all values in the row field and then show the one (out of about 10k) that I want to show (hiding 9,999 doesn't sound ilke the right approach).

Is there an easy way to do this or another way to do this? I want to avoid hiding rows manually in the VBA and would rather directly address the pivot field, just to keep my extraneous formulas on the same sheet stable.

Thanks!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
This thread shows how to use two or more cells with DataValidation dropdowns to set pivotfilters.

http://www.mrexcel.com/forum/showthread.php?t=575835

Regarding the best way to set a row field with 10,000 items to just show one, in VBA I don't think there is any way to code: "hide all pivotitems for this rowfield then unhide this one pivotitem". Excel wants you to have at least one item set to visible at all times in VBA.

The two best approaches that I know of are:
1. Set your one pivotitem to visible= true, then step through each pivot item, testing each items visible state and only hiding it if it is currently visible. (This is the approach in the linked example).

2. Temporarily change the Orientation of the Pivotfield to xlPageField. When it's a PageField you can clear all the filters and just set the one you want. Then reset the Orientation to RowField and reset the Position.

The second option has the potential to run faster for a large number of pivotitems; however more things can go wrong if you don't reset everything back the same way as it was before changing orientation.
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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