Pivot Table VBA Filter

chaddres

Board Regular
Joined
Jun 14, 2014
Messages
144
Office Version
  1. 365
Platform
  1. Windows
In my VBA code for my PivotTable, I have the below items hard coded. Is there a way to make the dates that I want to set to False relative? So, I want the date in Sheet1 J1 to be in place of "1/16/23" in the first row below. Is this possible?

VBA Code:
    With ActiveSheet.PivotTables("PivotTable075342").PivotFields("DOB")
        .PivotItems("1/16/23").Visible = False
        .PivotItems("1/17/23").Visible = False
        .PivotItems("1/18/23").Visible = False
        .PivotItems("1/19/23").Visible = False
    End With
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Have you tried...

VBA Code:
.PivotItems(Worksheets("Sheet1").Range("J1").Value).Visible = False


???
 
Upvote 0
What value does cell J1 actually contain?

Does it contain a true date value?

Or does it contain a text value that Excel can recognize as a date? If the latter, try...

VBA Code:
.PivotItems(CDate(Worksheets("Sheet1").Range("J1").Value).Visible = False

Does this help?

If not, can you post a small sample of your data, along with the pivottable, using the xl2BB add-in?
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,450
Members
449,453
Latest member
jayeshw

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