View Single Post
 
Old 02-22-2016, 12:30 PM
mbesspiata mbesspiata is offline Windows 7 64bit Office 2010 64bit
Advanced Beginner
 
Join Date: Mar 2011
Location: Virginia
Posts: 57
mbesspiata is on a distinguished road
Question Include and Exclude items through vba in pivot table

I need to create a macro to use on monthly reports where I can include only certain vendor number from a list of 100 or more (number changes each month). I need to include these certain ones ONLY each time. I've create this vba but it's not working for some reason. Is there a better way or what changes are needed in this formula:
Dim pItem As PivotItem
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("Vndr Id Cd")
For Each pItem In .PivotItems
If (pItem = "2304013") Then pItem.Visible = True
If (pItem = "2706002") Then pItem.Visible = True
If (pItem = "2706003") Then pItem.Visible = True
If (pItem = "4601504") Then pItem.Visible = True
If (pItem = "5201064") Then pItem.Visible = True
If (pItem <> "2304013") Then pItem.Visible = False
If (pItem <> "2706002") Then pItem.Visible = False
If (pItem <> "2706003") Then pItem.Visible = False
If (pItem <> "4601504") Then pItem.Visible = False
If (pItem <> "5201064") Then pItem.Visible = False
If (pItem = "(blank)") Then pItem.Visible = False
Next
End With


Mike
Reply With Quote