Pivot Table VBA Question

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
767
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

Is there a way to use two cell references (A1 From Date & A2 To Date) to update a filter in a pivot table without actually showing the filter itself?

I have used the following code to align a name of the person who loads the file so they can only see their data, but I am insure how I would get the
"ActiveSheet.PivotTables("AgentManager").PivotFields("Call Date")" to look between the first date ("A1") and the final date ("A2"), is this something that can be done.

Code:
Sub AgentManagerAlign()

Dim pvFld As PivotField
Dim strFilter As String

   Set pvFld = ActiveSheet.PivotTables("AgentManager").PivotFields("Team Manager")
   strFilter = ActiveWorkbook.Sheets("LiveStaffLoader").Range("B5").Value
   pvFld.CurrentPage = strFilter

End Sub

thanks in advance
Gavin
 
Sorry @SpillerBD, no set timescale as I am trying to make data smother to acces at the moment
I was actually suggesting using the TimeLine available. I haven't looked at the code created if recording a macro on changes to the timeline or how useful it might be.
In your macro, are you stepping through the code with items in the watch window to see the values assigned to variables as the macro progresses?
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Yes, it always fails where the value it looks up against the range ie week number
 
Upvote 0
Good afternoon all,

I have managed to cover the original problem by the following

Create your pivot table as needed with the filters as selectable fields (in the first instance while setting up)

Code:
Dim pvFld As PivotField
Dim strFilter As String
    
    Sheets("NameOfSheet").Select ' where the pivot table first filter is
    Range("G9").Select
            Set pvFld = ActiveSheet.PivotTables("PivotTableName").PivotFields("Team Manager")
            strFilter = ActiveWorkbook.Sheets("Source").Range("B4").Value ' where your filter is automatically identified, mine is a load page that holds various info
            pvFld.CurrentPage = strFilter
                Set pvFld = ActiveSheet.PivotTables("PivotTableName").PivotFields("Year")
                strFilter = ActiveWorkbook.Sheets("Source").Range("B17").Value ' where your filter is automatically identified, mine is a load page that holds various info
                pvFld.CurrentPage = strFilter
                    Set pvFld = ActiveSheet.PivotTables("PivotTableName").PivotFields("Week No")
                    strFilter = ActiveWorkbook.Sheets("Source").Range("B18").Value ' where your filter is automatically identified, mine is a load page that holds various info
                    pvFld.CurrentPage = strFilter

This is currently working on my example as I have then hidden all the rows that have the filters showing on and added slicers for ease of data manipulation by the users of the filr.

thanks
 
Upvote 0
Solution

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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