Loop through values in a pivottable and show/hide detail based on condition

Truth_Is_A_Person

New Member
Joined
May 24, 2018
Messages
3
here is my code that used to work, but for some reason now, it is not hiding the detail...

Code:
    For r = TopOfPivotTable To BottomOfPivotTable
   
        If Cells(r, 2).Value = "1" Then
            fname = Cells(r, 1).PivotField.Name
            Worksheets("Execution for RCA").PivotTables("PivotTable4").PivotFields(fname).PivotItems(Cells(r, 1).Text).ShowDetail = False
        Else
            fname = Cells(r, 1).PivotField.Name
            Worksheets("Execution for RCA").PivotTables("PivotTable4").PivotFields(fname).PivotItems(Cells(r, 1).Text).ShowDetail = True
        End If
        
        'double check incase the bottom row changes
        If InStr(Cells(r + 1, 1).Text, "Grand") Then Exit For
     
    Next r
essentially i am checking the Percent executed in column B and if it is 100 then hide the detail, if it is any other value then show the detail.
ZPn6C1U
UXpBPUT
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
i fixed it, i had declared fname as a string - when i commented out that declaration it worked perfectly. Moral of the story. data types matter(?)
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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