Results 1 to 10 of 10

Updating PivotTable filters based on other cell value

Threaded View

  1. #1
    Registered User
    Join Date
    02-01-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    15

    Updating PivotTable filters based on other cell value

    Hi there guy/girls!

    Hope youre well.

    Im using the following bit of code to try and get the filter of a pivottable to change based on the text displayed in a cell on the data sheet.

    ' CHANGES THE NAME IN THE CUSTOMER CONTACTS PIVOT TABLE
    
        Dim pvtTable As PivotTable
        Dim pvtField As PivotField
        Dim pvtItem As PivotItem
        Dim filterName As String
        
        Set pvtTable = Worksheets("Contacts").PivotTables("PivotTable10")
        Set pvtField = pvtTable.PivotFields("Opportunity Owner: Full Name")
        
        filterName = Worksheets("Data").Range("B1")
        
        For Each pvtItem In pvtField.PivotItems
            If pvtItem.Value = filterName Then
                pvtField.CurrentPage = filterName
                Exit For
            End If
        Next pvtItem
    This works great! The problem ive got is if say "Joe Blogs" has made no customer contacts and his name is in Data!B1 the script will error. However is "Mary Smith" has made contacts and her name is in Data!B1 in the script will run, change the value and move on.

    Can anyone think of a way to make the script just set the value as "(BLANK)" if the selected name is Data!B1 has made no contacts?

    your help is greatly appreciated! My hair is falling out!

    Cheers,
    Dale
    Last edited by romperstomper; 04-06-2011 at 03:42 AM. Reason: change quote to code tags

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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