Sub pivot_table_select()
Dim field1 As String
Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim inp_array() As String
Dim i, j, pi_count, inp_count As Integer
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 Title" 'Please change appropriately
Set pf = pt.PivotFields(field1)
pf.ClearAllFilters
'For Each pi In pf.PivotItems
' pi.Visible = True
'Next pi
inp = InputBox("Please enter", , "Please separate multiple strings with a space") 'Separate multiple strings with a space
If Len(Trim(inp)) = 0 Then
MsgBox ("No input provided")
Exit Sub
End If
inp_array = Split(inp, " ")
inp_count = 0
For i = LBound(inp_array) To UBound(inp_array)
'store_array(i) = inp_array(i)
inp_count = inp_count + 1
Debug.Print inp_count
Next i
pf.PivotFilters.Add Type:=xlCaptionContains, Value1:="*" & inp_array(0) & "*"
inp_count = inp_count + 1
pi_count = 1
If UBound(inp_array) > 0 Then
For Each pi In pf.PivotItems
If pi.Visible Then
pi_count = pi_count + 1
For j = 1 To UBound(inp_array)
If InStr(1, pi.Name, inp_array(j), vbTextCompare) = 0 Then
pi.Visible = False
Exit For
End If
Next j
If pi_count Mod 100 = 0 Then
ActiveSheet.Cells(Int(pi_count / 100), 7) = pi_count
End If
End If
Next pi
End If
End Sub