使用以下代码获取Run-time error 1004 - Application-defined or object-defined error
- 之前我从未使用过.PivotFilters.Add
,但语法看起来是正确的... mySheet
存在于工作簿中,因此是PivotTable1
和字段Account Name
:
Sub TestFiltering()
Dim mySheet As Worksheet
Set mySheet = ThisWorkbook.Worksheets("Summary")
'Error here
mySheet.PivotTables("PivotTable1").PivotFields("Account Name").PivotFilters.Add Type:=xlCaptionDoesNotContain, Value1:="affiliate"
ActiveWorkbook.RefreshAll
End Sub