Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Use a UserForm TextBox to Filter a Pivot Table Field

$
0
0

Hi,

I have a pivot table that is being used for quick reference. I wanted to build a small user form with a text box that when filled will filter the pivot table and display only the line that contains the search criteria. It would be nice to have the pivot table filter as they are typing however a command button launch works too.

Does anyone know how to do this? Is there a better code to use? Currently the code does nothing when you type into the UserForm.

It returns a Run-Time Error '1004'

My code is as follows:

Sub TextBox1_Change()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim InputTaskName As String

Set pt = ActiveSheet.PivotTables("Pivot")
Set pf = pt.PivotFields("Location")

ApplicationDisplayAlerts = False
ApplicationScreenUpdating = False
On Error Resume Next

For Each pi In pt.PivotFields("Location")
Select Case pt.PivotFields("Location") = TextBox1
    Case True
    If pi.Value = TextBox1 Then
    If pi.Visible = True Then
    ElseIf pi.Value <> TexBox1 Then
    pi.Visible = False
    End If
    End If
    End Select
    Next pi


Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub



Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>