Pivot table search filter without exact match?

frewert

Board Regular
Joined
Apr 4, 2014
Messages
188
Office Version
  1. 365
Platform
  1. Windows
Can something be done to change the way a search filter works inside a pivot table?

If I search "Chicos blue" I want it to return all cells with "Chicos" and "blue", not just the "Chicos blue" exact match.

In other words, if I separate my search filter queries by space, the space would act like the AND operator.

1718567486777.png

Thanks!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi

In the filter text field (Search field), when you type "Blue" after having typed "Chicos", there would be an option appearing at the top of the filter- "Add selection to the current filter". Selecting that would keep both options
 
Upvote 0
Hi

In the filter text field (Search field), when you type "Blue" after having typed "Chicos", there would be an option appearing at the top of the filter- "Add selection to the current filter". Selecting that would keep both options
When I do that, the first selection goes away.

1.) type Chicos
2.) press enter
3.) type blue
4.) press add to selection
5.) press enter
6.) Chicos goes away.
 
Last edited:
Upvote 0
In Step 5, please press Space instead of Enter
The Space only checks or unchecks Add selection to the current filter

In both cases, typing in "blue" will select all listings with "blue" in it. Instead of only selecting listings with Chicos AND blue
 
Upvote 0
Sorry, my understanding had been wrong

I had interpreted it to be chicos OR blue

Please find a VBA code below, which would be of help to select fields separated by a space (say chicos AND blue)

Please change field1, marked as 'Colour' here appropriately to reflect the actual column which you need to filter

VBA Code:
Sub pivot_table_select()

    Dim input1 As String
    Dim input2 As String
    Dim field1 As String
    Dim ws As Worksheet
    
    Dim pt As PivotTable
    Dim pf As PivotField
    Dim pi As PivotItem
    
    Dim store_array(0 To 10) As String
    Dim inp_array() As String
    Dim i, j As Integer
          
    
    For i = LBound(store_array) To UBound(store_array)
        store_array(i) = ""
    Next i
                
    Set ws = ThisWorkbook.ActiveSheet
    If ws.PivotTables.Count > 0 Then
        Set pt = ws.PivotTables(1)
    Else
        MsgBox ("No pivot table")
            Exit Sub
    End If
    
    field1 = "Colour" 'Please change appropriately
    
    Set pf = pt.PivotFields(field1)
                
    inp = InputBox("Please enter")
    
    If InStr(1, inp, " ", vbTextCompare) > 0 Then
        ReDim inp_array(0 To InStr(1, inp, " ", vbTextCompare))
        inp_array = Split(inp, " ")
    Else
        ReDim inp_array(0 To 0)
        inp_array(0) = inp
    End If
    
    inp_count = 0
        
    For i = LBound(inp_array) To UBound(inp_array)
        store_array(i) = inp_array(i)
        inp_count = inp_count + 1
    Next i
            
    For Each pi In pf.PivotItems
        pi.Visible = True
        
        For j = 0 To inp_count - 1
            If InStr(1, pi.Name, store_array(j), vbTextCompare) = 0 Then
                pi.Visible = False
                Exit For
            End If
        Next j
        
    Next pi

End Sub
 
Upvote 0
I tried your code but it ended up looping continuously. Maybe I have entered the wrong thing for "colour".

The Pivot Table field to search is called "Item Title"

This is what I replaced "colour" with in the code.

Was I supposed to use "Slicer_Item_Title" instead?

Another thing to point out. I have made a duplicate Pivot Table that is hidden. This copy of PivotTable1 is giving me the ability to do a search filter. The technique I learned from a Youtube tutorial,

I removed the second pivot table and tried again. Still the looping behavior is present.
 

Attachments

  • Capture.JPG
    Capture.JPG
    105.5 KB · Views: 1
Upvote 0
Just a small modification to the code

Please check this; it is working well for me

Changed field 1 to "Item Label" (heading in the source data column)

This looks at the first pivot table in a given sheet

VBA Code:
Sub pivot_table_select()

    Dim input1 As String
    Dim input2 As String
    Dim field1 As String
    Dim ws As Worksheet
    
    Dim pt As PivotTable
    Dim pf As PivotField
    Dim pi As PivotItem
    
    Dim store_array(0 To 10) As String
    Dim inp_array() As String
    Dim i, j As Integer
          
    
    For i = LBound(store_array) To UBound(store_array)
        store_array(i) = ""
    Next i
                
    Set ws = ThisWorkbook.ActiveSheet
    If ws.PivotTables.Count > 0 Then
        Set pt = ws.PivotTables(1)
    Else
        MsgBox ("No pivot table")
            Exit Sub
    End If
    
    field1 = "Item Label" 'Please change appropriately
    
    Set pf = pt.PivotFields(field1)
    
    For Each pi In pf.PivotItems
        pi.Visible = True
    Next pi
                
    inp = InputBox("Please enter")
    
    If InStr(1, inp, " ", vbTextCompare) > 0 Then
        ReDim inp_array(0 To InStr(1, inp, " ", vbTextCompare))
        inp_array = Split(inp, " ")
    Else
        ReDim inp_array(0 To 0)
        inp_array(0) = inp
    End If
    
    inp_count = 0
        
    For i = LBound(inp_array) To UBound(inp_array)
        store_array(i) = inp_array(i)
        inp_count = inp_count + 1
    Next i
            
    For Each pi In pf.PivotItems
               
        For j = 0 To inp_count - 1
            If InStr(1, pi.Name, store_array(j), vbTextCompare) = 0 Then
                pi.Visible = False
                Exit For
            End If
        Next j
        
    Next pi

End Sub
 
Upvote 0
I get, Error 400

I don't see where "Item Label" is found. My source data table is as follows:
Item TitleSold ForShippingSale DateDays Til SoldRateSizeCategoryGenderCondition
Maeve Athropologie Sweater Poncho Womens One Size Turtleneck Sleeveless32.9876/13/202452173%One SizeSweatersWomensPre-owned
Old Navy Denim Shirt Womens 4X Pockets Cotton Blue Long Sleeve Button Up22.488.66/13/202422409%4XTopsWomensPre-owned
Fabletics The Only Pant Classic Fit Mens 42X28 Purple Polyester Spandex Zip24.9876/13/202421143%42PantsMensPre-owned
Lacoste Button Front Shirt Mens 42 Large L Cotton Long Sleeve Purple Pocket13.9476/13/202436250%LTopsMensPre-owned
Foxxy T-Shirt Dress Womens 2X Black White Stripe Rayon Stretch Short Sleeve6.7876/13/202432228%2XTopsWomensPre-owned
Forever 21 NWT 2" Denim Shorts Mid Rise Stretch Blue Womens 251.685.56/12/202469513%25ShortsWomensNew
Polo Ralph Lauren Dress Shirt Philip Mens 16 32/33 Blue Striped Cotton LS9.445.56/12/202470129%33TopsMensPre-owned
Alfani NWT T-Shirt End on End Tee Stretch Red V-Neck Short Sleeve Tech Mens M8.485.56/12/202447619%MTopsMensNew
Orvis Pants Womens Large Pull On 100% Linen Brown Drawstring Elastic Waist15.2876/12/202419746%LPantsWomensPre-owned
Christian Siriano New York Dress Womens 2XL XXL Teal Snake Print Shift Stretch V11.6876/12/202410784%2XLDressesWomensPre-owned
Tommy Bahama Silk Shirt Mens Large Pink Plaid Short Sleeve Button Front9.985.56/11/20249199%LTopsMensPre-owned
Brooks Brothers Polo Shirt Mens XL Long Sleeve Cotton Original Fit Red19.9876/11/202428321%XLTopsMensPre-owned
Essentials By Maggie Barnes Button Front Shirt Womens 32/32 4X Cotton Plaid13.9476/10/202483108%4XTopsWomensPre-owned
Knox Rose NWT Target Blouse Top Shirt Blue Sleeveless Rayon Womens M11.685.56/10/202447419%MTopsWomensNew
Chicos Dress Womens Size 3 (US XL) Blue Green Teal Paisley 3/4 Sleeve Stretch26.9876/10/202411777%XLDressesWomensPre-owned
Ruby Rd Blouse Womens 2X Rayon Spandex Beige Tank Top With Sheer Sleeves11.6876/9/202410784%2XTopsWomensPre-owned
Kirkland 100% Cashmere Sweater Polo Mens XL Brown Cable Knit Signature41.9876/9/202423391%XLSweatersMensPre-owned
LOFT Ann Taylor NWT Skirt Womens 10 Cotton A-Line Pleated Side Zip Short9.186/9/202419446%10ShortsWomensNew
Ann Taylor NWT Dress Womens Large Black/White Fit Flare Sleeveless Stretch19.296/9/202422141%LDressesWomensNew
American Eagle Curvy Super Hi Rise Shortie Blue Denim Shorts Womens 88.9876/9/202471013%8ShortsWomensPre-owned
Diana Lyne USA T-Shirt Womens 2X Cotton Polyester Purple Short Sleeve13.4876/8/202423391%2XTopsWomensPre-owned
Coldwater Creek Blouse Womens Large 14/16 Silk Relaxed Short Sleeve Pocket11.685.56/8/202416455%LTopsWomensPre-owned
Alfred Dunner Blouse Womens Large Lace Short Sleeve Blue Green Lined Knot Front9.885.56/8/202418050%LTopsWomensPre-owned
Under Armour T-Shirt Mens XL Blue Polyester Short Sleeve Crew Logo HeatGear8.985.56/8/202410685%XLTopsMensPre-owned
Lucky Brand Blouse Womens 2X White Floral Pullover Rayon Long Sleeve Tie19.985.56/8/202417252%2XTopsWomensPre-owned


Here is a link to the actual workbook, My Sold Research Tool v3.xlsm
 
Upvote 0
I don't see where "Item Label" is found. My source data table is as follows:
If you look at the code he posted, he has this line:
VBA Code:
    field1 = "Item Label" 'Please change appropriately
The "Please change appropriately" is a cue to you to change the value to match your data!

Based on your image, it looks like you will want to change that to:
VBA Code:
    field1 = "Item Title" 'Please change appropriately
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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