Pivot Table Filtering

peteruhl23

New Member
Joined
Mar 29, 2018
Messages
2
cheers everybody,

I'm a newbie to VBA and decided to undertake a task to automate a report regarding supplier evaluation.

I have managed to automate all the actions needed to provide input data to my final excel sheet, created UserForm and ListBox and got to the point where my code copies selected items from listbox and pastes it to a new column

Anybody using my code, can select anywhere from 1-20 suppliers (that is 1-20 items from the listbox). Depending on their selection, I need my code to take the selection user made and filter my PivotTable based on that.
Put differently, say the user has selected suppliers X,Y,Z so what I need my Pivot to do is to show X,Y,Z suppliers but exclude A,B,C suppliers.

Here's the code I was able to find on a different webpage, but it didnt seem to work. I am using excel 2016. The other users said it worked for them but doesnt seem to work for me. The message I get is" Unable to get the PivotFields property of the PivotTable class"

Is there any way you guys can help me out?

Cheers

Dim pt As PivotTable, pi As PivotItem
Set pt = PIVOTALLKPI.PivotTables("PivotTable2")
Dim i As Long
With Me
For Each pi In pt.PivotFields("Supplier").PivotItems
pi.Visible = Not (wksData.Columns("E").Find(what:=pi.Name, lookat:=xlWhole, LookIn:=xlValues) Is Nothing)
Next
End With
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Dose the PivotTable name actually exist, so the referencing will work
 
Upvote 0
Dose the PivotTable name actually exist, so the referencing will work

Hi,

sure, everything is set correctly regarding pivotable names (i.e. PivotTable2 is the actual pivot table in my worksheet and I also defined PIVOTALLKPI as worksheet, just didnt show it here.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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