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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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