I am so new to this that I might not even ask the question correctly. The question is stated in the title (PivotTable Filter As You Type) with a goal to convert some code that works on a table, and make it work for a PivotTable.
So far I have PivotTable named "BudgetVar" that also has a column (field?) labeled "Description".
I have created an ActiveX Text Box named "TextBox1" that is "LinkedCell" to an empty cell; Cell D7.
To test part of the code, I found I can type into the TextBox1 and it does link (type the same string) into cell D7 using this code:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End Sub
The original code (for a Table that is not a PivotTable) is:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
ActiveSheet.ListObjects("BudgetVar").Range.AutoFilter Field:=2, Criteria1:= "*" & [D7] & "*", Operator:=xlFilterValues
Application.ScreenUpdating = True
End Sub
The new similar code I found for a PivotTables is:
Sub FilterBasedOnVariable()
Dim myPivotField As PivotField
Dim filterValue As String
Set myPivotField = ActiveSheet.PivotTables("BudgetVar").PivotFields("Description")
filterValue = ActiveSheet.Range(" * " & [D7] & " * ").Value
myPivotField.CurrentPage = filterValue
End Sub
I tried to combine them into this, but I am failing horribly:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
FilterBasedOnVariable()
Dim myPivotField As PivotField
Dim filterValue As String
Set myPivotField = ActiveSheet.PivotTables("BudgetVar").PivotFields("Description")
filterValue = " * " & [D7] & " * "
myPivotField.CurrentPage = filterValue
Application.ScreenUpdating = True
End Sub
Maybe I should be asking how to initiate the sub FilterBasedOnVariable() and get rid of sub textbox1_Change()?
So far I have PivotTable named "BudgetVar" that also has a column (field?) labeled "Description".
I have created an ActiveX Text Box named "TextBox1" that is "LinkedCell" to an empty cell; Cell D7.
To test part of the code, I found I can type into the TextBox1 and it does link (type the same string) into cell D7 using this code:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End Sub
The original code (for a Table that is not a PivotTable) is:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
ActiveSheet.ListObjects("BudgetVar").Range.AutoFilter Field:=2, Criteria1:= "*" & [D7] & "*", Operator:=xlFilterValues
Application.ScreenUpdating = True
End Sub
The new similar code I found for a PivotTables is:
Sub FilterBasedOnVariable()
Dim myPivotField As PivotField
Dim filterValue As String
Set myPivotField = ActiveSheet.PivotTables("BudgetVar").PivotFields("Description")
filterValue = ActiveSheet.Range(" * " & [D7] & " * ").Value
myPivotField.CurrentPage = filterValue
End Sub
I tried to combine them into this, but I am failing horribly:
Private Sub TextBox1_Change()
Application.ScreenUpdating = False
FilterBasedOnVariable()
Dim myPivotField As PivotField
Dim filterValue As String
Set myPivotField = ActiveSheet.PivotTables("BudgetVar").PivotFields("Description")
filterValue = " * " & [D7] & " * "
myPivotField.CurrentPage = filterValue
Application.ScreenUpdating = True
End Sub
Maybe I should be asking how to initiate the sub FilterBasedOnVariable() and get rid of sub textbox1_Change()?