for sure this
Set pvtTable = ActiveSheet.PivotTables("PivotTable1").PivotFields("END DATE")
For Each pvtFld In pvtTable.PivotFields
is wrong as you try to assign a PivotField object to PivotTable variable.
proper code shall be:
Set pvtTable = ActiveSheet.PivotTables("PivotTable1")
For Each pvtFld In pvtTable.PivotFields
I don't want to produce dummy data to test your issue but may be (?) the problem is with data stored in enddate type? May be it's not date type?
You may test it that way:
Dim pvtFld As PivotField
Dim pvtTable As PivotTable
Set pvtTable = ActiveSheet.PivotTables("PivotTable1")
For Each pvtFld In pvtTable.PivotFields
If pvtFld.Name Like "*END DATE*" Then
Select Case pvtFld.DataType
Case Is = xlText
MsgBox "The field contains text data"
Case Is = xlNumber
MsgBox "The field contains numeric data"
Case Is = xlDate
MsgBox "The field contains date data"
End Select
End If
Next pvtFld
Set pvtTable = Nothing
But general comment by gijsmo that with sample file we could test it is 100% valid
Bookmarks