Hello,

I have developed a combo box that lets a user chose an employee. Each employee has some programs and then program data that changes over time. I am trying to have the user chose the employee and then 2 data set dates (as contained in the underlying data) and then create a pivot table comparing the two dates.

I am having a very hard time on setting the 2 dates to compare. If I record a macro everything is fine, except it uses the pivotItems visible true/false approach. I am trying make the pivot filter to be the date variable chosen by the user.

With my limited VBA skills whenever I try to reference the combo box response as a variable i get the dreaded "Unable to get pivot type property". The really frustrating thing is that I got this method to work like a charm on the employee combo box chosen as a page field.

Any help would be greatly appreciated

HTML Code: 
Option Explicit

Private Sub OKButton_Click()



Dim Employee As String
Dim DataDate1 As Date
Dim DataDate2 As Date

Employee = EmployeeComboBox.value
DataDate1 = DataDateComboBox1.value
DataDate2 = DataDateComboBox2.value

 Dim pt As PivotTable
    Dim strField As String
    Dim WSD As Worksheet
    Set WSD = Worksheets("Data")
    Dim PTOutput As Worksheet
    Set PTOutput = Worksheets("Summary")
    Dim PTCache As PivotCache
    Dim PRange As Range
    Dim PTItem As PivotItems


    

 Sheets("Summary").Select
    Cells.Select
    Selection.Clear

    ' Find the last row with data
    Dim finalRow As Long
    finalRow = WSD.Cells(Application.Rows.Count, 1).End(xlUp).Row
    
    ' Find the last column with data
    Dim finalCol As Long
    finalCol = WSD.Cells(1, Application.Columns.Count).End(xlToLeft).Column
    
    ' Find the range of the data
    

    Set PRange = WSD.Cells(1, 1).Resize(finalRow, finalCol)
    Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange)

    ' Create the pivot table
    Set pt = PTCache.CreatePivotTable(TableDestination:=PTOutput.Cells(3, 1), _
    TableName:="Comparison")
    


    With ActiveSheet.PivotTables("Comparison").PivotFields("Sub Program")
        .PivotItems("(blank)").Visible = False
    End With

    With ActiveSheet.PivotTables("Comparison").PivotFields("Employee")
        .Orientation = xlPageField
        .Position = 1
    End With
    
    ActiveSheet.PivotTables("Comparison").PivotFields("Employee"). _
        CurrentPage = Employee
     
        
    With ActiveSheet.PivotTables("Comparison").PivotFields("SpendType")
        .Orientation = xlRowField
        .Position = 1
    End With
    
    With ActiveSheet.PivotTables("Comparison").PivotFields("Sub Program")
        .Orientation = xlRowField
        .Position = 2
    End With
    
    
 With ActiveSheet.PivotTables("Comparison").PivotFields("Data Date")
        .Orientation = xlColumnField
        .Position = 1
    End With
    
    With ActiveSheet.PivotTables("Comparison").PivotFields("Data Date")
        .PivotItems("11/30/2012").Visible = False
        .PivotItems("1/11/2013").Visible = False
    End With
    
     ActiveSheet.PivotTables("Comparison").AddDataField ActiveSheet.PivotTables( _
        "Comparison").PivotFields("Jan"), "Sum of Jan", xlSum
        
        End Sub