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
Bookmarks