Setting PivotItems visibility

James McMillan

New Member
Joined
Jan 18, 2011
Messages
3
I have created the following coded to filter a pivot table:

ActiveSheet.PivotTables("PivotTable1").PivotFields("G/L Acct").ClearAllFilters

With ActiveSheet.PivotTables("PivotTable1").PivotFields("G/L Acct")

For i = 1 To .PivotItems.Count
If .PivotItems(i).Value = "066930" Or "077697" Then
.PivotItems(i).Visible = True
Else
.PivotItems(i).Visible = False
End If
Next
End With

If I set the PivotItems.value to just one value, the code works, but if I try to set it to equal more than one value it does not. Am I using the OR function correctly?

Thanks for your help.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Welcome to the Board!

Kinda ... you are using the OR correctly, but not stating your 2nd condition correctly. Try this line instead:

Code:
If .PivotItems(i).Value = "066930" Or .PivotItems(i).Value = "077697" Then
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,024
Members
448,543
Latest member
MartinLarkin

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