title: Filtering a Pivot Table based on text string in a cell
body: <p>I have the following code:</p>
  
  <pre><code>Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      If Intersect(Target, Range("K2:K3")) Is Nothing Then Exit Sub
  
      Dim pt As PivotTable
      Dim Field As Variant
      Dim NewCat As String
      Set pt = Worksheets("Fact Trans").PivotTables("PivotTable1")
      Set Field = pt.PivotFields("[Locations].[Loc Name].[Location Name]")
      NewCat = Worksheets("Fact Trans").Range("K2").Value
      With pt
          Field.ClearAllFilters
          Field.CurrentPage = NewCat
          pt.RefreshTable
      End With
  
  End Sub
  </code></pre>
  
  <p>So as you can see I'm trying to change my pivot table based on the value in K2, but I keep getting the error "Run-time error '1004': Unable to set CurrentPage property of the PivotField class"  and debug highlight's line "Field.CurrentPage = NewCat"  .</p>
  
  <p>Any insight on why and how I can get this code to work will be great.</p>