Hi,

I have the following code for filtering a pivot table on an active cell:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This brings value out value of active cell.
Range("L19").Value = ActiveCell.Value

'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String

'Here you amend to filter your data
Set pt = Worksheets("Finance Report").PivotTables("PivotTable10")
Set Field = pt.PivotFields("Account2")
NewCat = Worksheets("Finance Report").Range("L19").Value

'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With

End Sub


This code works awesome as long as the active cell is a valid filter value however if it is not(IE a blank cell or a value that is not in Account2) then I receive the following error:
Run-time error '1004': Application-defined or object-defined error

Does anyone know if there any way to make the pivot table change only if a valid value is selected?

Any help is greatly appreciated.