I have a Pivot table on Sheet "Purchases" and would like macro to select the "Blank" from filter drop down in A2 if Cell C10 on sheet "Recon" is zero, otherwise select highest year from Filter
I have attached sample data
It would be appreciated if someone could assist me
I have also posted on https://www.mrexcel.com/forum/excel-...sed-value.html
See my code below which I cannot get to work as per my criteria
If C10 on sheet 'Recon" is zero then filter must be "Blank", otherwise select Highest Year in filter , based on max year on "Raw Data"
![]()
sub ShowSelectFields() Dim pt As PivotTable Dim pi As PivotItem Sheets("purchases").Select On Error GoTo ErrorHandler Application.ScreenUpdating = False Set pt = ActiveSheet.PivotTables("PivotTable2") pt.ManualUpdate = True With ActiveSheet.PivotTables("PivotTable5").PivotFields("Financial Year") .PivotItems("(blank)").Visible = True End With 'turn off all pivot table items except "blank" For Each pi In pt.PivotFields("Financial Year").PivotItems Select Case pi.Value Case 1 To 5 pi.Visible = False Case Else pi.Visible = True End Select Next pi pt.ManualUpdate = False 'turn on your desired selection of pivot table items num = 1 For i = 1 To ActiveSheet.Range("J1") mSelect1 = ActiveSheet.Range("J1" & num) With ActiveSheet.PivotTables("PivotTable2").PivotFields("Financial Year") .PivotItems(mSelect1).Visible = True .PivotItems("(blank)").Visible = False ' turn off blanks End With num = num Next i Application.ScreenUpdating = True Exit Sub ErrorHandler: Application.ScreenUpdating = True End Sub











LinkBack URL
About LinkBacks
Register To Reply
Bookmarks