Hi again,
I am using a PivotTable to create some reports (using PivotSelect and Count etc). I actually want to look at the data month by month so I have written this
Sub RestrainPivotToMonths(WhichMonth As Integer)
On Error Resume Next
Windows("Transactions Master.xls"
.Activate
With ActiveSheet.PivotTables("PivotTable1"
.PivotFields("Tra-Transaction date"
For Each pit In .PivotItems
If Month(DateValue(pit)) = WhichMonth Then pit.Visible = True Else pit.Visible = False
Next
End With
End Sub
which will only include dates matching a desired month. ie RestrainPivotToMonths 6 will limit entries to those in June. However, this doesn't appear to be very efficient - I could add a column to the PivotData Source but the purpose is that I will eventually be able to Input a Start and To date to allow a query on any timeframe. Any suggestions on how best to improve this? Particularly, can you limit the PivotTable to only look at a subset of data in the first place? (I tried autofiltering the source data but with no luck!)
Thanks in advance and for all you helps so far.
Cheers,
Ig
I am using a PivotTable to create some reports (using PivotSelect and Count etc). I actually want to look at the data month by month so I have written this
Sub RestrainPivotToMonths(WhichMonth As Integer)
On Error Resume Next
Windows("Transactions Master.xls"
With ActiveSheet.PivotTables("PivotTable1"
For Each pit In .PivotItems
If Month(DateValue(pit)) = WhichMonth Then pit.Visible = True Else pit.Visible = False
Next
End With
End Sub
which will only include dates matching a desired month. ie RestrainPivotToMonths 6 will limit entries to those in June. However, this doesn't appear to be very efficient - I could add a column to the PivotData Source but the purpose is that I will eventually be able to Input a Start and To date to allow a query on any timeframe. Any suggestions on how best to improve this? Particularly, can you limit the PivotTable to only look at a subset of data in the first place? (I tried autofiltering the source data but with no luck!)
Thanks in advance and for all you helps so far.
Cheers,
Ig