selecting certain items in a pivot dropdonw in vba code

charlie_c

New Member
Joined
Sep 1, 2017
Messages
2
hi, I am trying to find code that will select certain dates in a pivot table dropdown after it has been refreshed. The dropdown will have boxes for dates and the code should select all the months after today's date or between certain dates. thx. Using the macro recorder I have the following, but the dates are hard coded and I need it to be flexible. thx.

Code:
Sub MacRecord()
    ActiveSheet.PivotTables("PivotTable1").PivotFields("need by").CurrentPage = _
        "(All)"
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("need by")
        
        .PivotItems("9/1/2017").Visible = True
        .PivotItems("10/1/2017").Visible = True
        .PivotItems("11/1/2017").Visible = True
        .PivotItems("12/1/2017").Visible = True
    End With
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
something like
Code:
Sub MacRecord()
Dim Pi As PivotItem
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Need By").CurrentPage = _
        "(All)"
    With ActiveSheet.PivotTables("PivotTable1")
        For Each Pi In .PivotFields("Need By")
            If Pi.Value > Date Then
                Pi.Visible = True
            End If
        Next
    End With
End Sub
 
Upvote 0
thx tinbendr. but I get a run-time error '438', object doesn't support this property or method in the "For Each Pi In .PivotFields("Need By")" line of code.
 
Upvote 0
I'll have to have a link to the file or sample file to proceed.

You can also email a sample file to my username @ gmail
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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