I am trying to compare and filter dates, that are grouped weekly, in two different pivot tables in two different worksheet. I want to compare the dates in the two table and if they are the same then copy that grouped date and put it in another worksheet. The VBA code that I have is comparing all the dates within a month. For example:
pivot table 1 pivot table 2
10/15/2013 - 10/21/2013 10/15/2013-10/21/2013
10/22/2013 - 10/28/2013 10/22/2013 - 10/28/2013
5/27/2014 - 6/2/2014 6/3/2014 - 6/9/2014
When I run the VBA I want to copy the first two sets of dates into another worksheet because they are the same and ignore the third set because they aren't. The number of dates in each table could be different. Here is the code I have so far
Sub Find()
Dim Pvt1 As PivotTable
Dim Pvt2 As PivotTable
Dim pf1 As PivotField
Dim pf2 As PivotField
Dim pi1 As PivotItem
Dim pi2 As PivotItem
Dim cell As Range
Set Pvt1 = ActiveWorkbook.Worksheets("Total Bloodhound").PivotTables("PivotTable3")
Set Pvt2 = ActiveWorkbook.Worksheets("Total Closed").PivotTables("PivotTable1")
Set pf1 = Pvt1.PivotFields("time")
Set pf2 = Pvt2.PivotFields("time")
Dim index As Integer
index = 1
For Each pi1 In pf1.PivotItems
For Each pi2 In pf2.PivotItems
If IsEmpty(pi2.Value) Then Exit For
If pi1.Value = pi2.Value Then
Worksheets("Sheet1").Cells(index, "A") = pi1.Value
index = index + 1
End If
Next pi2
Next pi1
End Sub
This code compares and copies all the dates with a month even though those dates are not in the pivot table. Any help would be great thanks!