Pivot table search

jcaptchaos2

Well-known Member
Joined
Sep 24, 2002
Messages
1,032
Office Version
  1. 365
Platform
  1. Windows
i am trying to make it so a user can type something in a cell press a macro button and the pivot table will filter for that word. I can do it manually by selecting the drop down, selecting label filters and typing my search word in. I want the user to be able to type the search word in cell B1 hit the button and it does that for them I have this but don't know how to get it to look at what's typed in the cell. Is it possible to do this?

Code:
Sub bllookup()
'
' bllookup Macro
'

'
    Range("B1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveSheet.PivotTables("PivotTable2").PivotFields("Description").PivotFilters. _
        Add Type:=xlCaptionContains, Value1:=("B1")
    Range("F1").Select
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
(Untested) Try:

Code:
Sub bllookup()
'
' bllookup Macro
'

'
Dim FilterVal as String
FilterVal = Range("B1").value
    

    ActiveSheet.PivotTables("PivotTable2").PivotFields("Description").PivotFilters. _
        Add Type:=xlCaptionContains, Value1:=FilterVal
    Range("F1").Select
End Sub
 
Upvote 0
I found this and have changed it to match my data but it stops on Field.Currentpage = NewCat

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
'This line stops the worksheet updating on every change, it only updates when cell
'B1 or B2 is touched
If Intersect(Target, Range("b1:b2")) Is Nothing Then Exit Sub
 
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim Newcat As String
 
'Here you amend to suit your data
Set pt = Worksheets("By Month").PivotTables("PivotTable2")
Set Field = pt.PivotFields("Description")
Newcat = Worksheets("By Month").Range("B1").Value
 
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = Newcat
pt.RefreshTable
End With
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,717
Members
449,050
Latest member
MiguekHeka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top