+ Reply to Thread
Results 1 to 2 of 2

Link VBA Pivot to a cell range for filter update

  1. #1
    Registered User
    Join Date
    08-11-2014
    Location
    England
    MS-Off Ver
    7
    Posts
    1

    Link VBA Pivot to a cell range for filter update

    Hi all,

    I have a vba script that makes a pivot table, works well, but I need to link the pivot table filter to a 'namedrange' cell on a spreadsheet. I have found the code below on google but can't seem to get it to work, when the cell is updated the pivot does not refresh??.... any idea's??


    Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim ws As Worksheet
    Dim pt As PivotTable
    Dim pi As PivotItem
    Dim strField As String

    strField = "Period (01/MM/YYYY)"

    On Error Resume Next
    Application.EnableEvents = False
    Application.ScreenUpdating = False

    If Target.Address = Range("SelectDate").Address Then

    ' For Each ws In ThisWorkbook.Worksheets
    Set ws = Me
    For Each pt In ws.PivotTables
    With pt.PageFields(strField)
    For Each pi In .PivotItems
    If pi.Value = Target.Value Then
    .CurrentPage = Target.Value
    Exit For
    Else
    .CurrentPage = "(All)"
    End If
    Next pi
    End With
    Next pt
    ' Next ws

    End If

    Application.EnableEvents = True
    Application.ScreenUpdating = True

    End Sub

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Link VBA Pivot to a cell range for filter update

    What exactly are you trying to accomplish?
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Pivot Filter based off drop down cell will not update in protected sheet
    By THAT guy 112073 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-30-2014, 01:03 PM
  2. Link and update a dynamic excel cell range to external jpeg image
    By oscar.mz15 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2013, 02:19 PM
  3. Update a pivot filter based on cell value by using a button
    By tray262 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-23-2013, 02:40 PM
  4. Filter Pivot based on Cell Value - Date Range
    By mfaustin in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-26-2013, 08:47 AM
  5. Update Pivot Report Filter Value based on cell updated by formula
    By carlwin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2013, 08:28 AM

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