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.
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Truth_Is_A_Person

New Member
Joined
May 24, 2018
Messages
3
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(?)
 

Watch MrExcel Video

Forum statistics

Threads
1,090,247
Messages
5,413,291
Members
403,472
Latest member
ArtisticOwl

This Week's Hot Topics

Top