Results 1 to 2 of 2

Macro to Select Blank or latest year on Pivot Filter

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Macro to Select Blank or latest year on Pivot Filter

    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
    Attached Files Attached Files
    Last edited by Pepe Le Mokko; 11-14-2019 at 03:25 AM. Reason: Highlighted link

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Select Automatic Report Filter in Pivot where Filter exist in Data table else select Blank
    By vinaynaran in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-02-2016, 08:47 AM
  2. VBA- Filter Pivot table based on latest and 2nd latest date in column
    By ziyan89 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 12-29-2015, 11:18 AM
  3. Macro to select rolling/latest 6 weeks in a pivot table
    By prasannakr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2013, 03:59 AM
  4. Replies: 5
    Last Post: 05-29-2013, 12:27 AM
  5. Replies: 2
    Last Post: 02-13-2012, 08:51 PM
  6. Select latest of 3 dates and skip blank cells
    By Skully in forum Excel General
    Replies: 16
    Last Post: 06-08-2011, 04:07 AM
  7. Macro to select first blank cell in filter for vlookup
    By prashant84 in forum Excel General
    Replies: 1
    Last Post: 08-22-2010, 02:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1