Results 1 to 1 of 1

VBA for Pivot Table Filters

Threaded View

  1. #1
    Registered User
    Join Date
    06-21-2010
    Location
    Texas, San Antonio
    MS-Off Ver
    Excel 2007
    Posts
    57

    VBA for Pivot Table Filters

    Hello,

    I am trying to build a worksheet which enables the user to key in certain data and then apply that data to a pivot table. I have some code to help me accomplish this, but it is not working. It does not apply my data to the pivot table. I have attached my workbook. Any help would be appreciated.

    
    Option Explicit
    
    Sub FilterPivotDates()
    '
    Dim dStart As Date
    Dim dEnd As Date
    Dim dname As String
    Dim pt As PivotTable
    Dim pf As PivotField
    Dim pn As PivotField
    Dim pi As PivotItem
    
    Application.ScreenUpdating = False
    On Error Resume Next
    
    dStart = Sheets("Reports").Range("StartDate").Value
    dEnd = Sheets("Reports").Range("EndDate").Value
    dname = Sheets("Reports").Range("DataSelection").Value
    
    Set pt = ActiveSheet.PivotTables(1)
    Set pf = pt.PivotFields("Date")
    Set pn = pt.PivotFields("Name")
    
    pt.ManualUpdate = True
    
    pf.EnableMultiplePageItems = True
    pn.EnableMultiplePageItems = True
    
    For Each pi In pf.PivotItems
      pi.Visible = True
    Next pi
    
    For Each pi In pf.PivotItems
      If pi.Value < dStart Or pi.Value > dEnd Then
        pi.Visible = False
      End If
    Next pi
    
    For Each pi In pn.PivotItems
      pi.Visible = True
    Next pi
    
    
    Application.ScreenUpdating = False
    pt.ManualUpdate = False
    
    Set pn = Nothing
    Set pf = Nothing
    Set pt = Nothing
    
    
    End Sub
    Thanks
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

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