Run Time Error 1004 'Unable to get the PivotFields property of the PivotTable class'

后端 未结 2 1924
别跟我提以往
别跟我提以往 2021-02-14 03:58

I realy have no Idea what this error means... I am trying to use the code to select all the rows under one of the subheaders in a pivot table. I am getting a run time error 100

2条回答
  •  眼角桃花
    2021-02-14 04:27

    I may add an extra answer (as I found nothing on that):

    For people working with Data Model Pivot Tables, field names are not obvious ([tablename].[fieldname].[fieldname2]). Hence I suggest using following loop to understand what fields are currently in your pivot table:

    Dim pt As PivotTable
    Dim pf As PivotField
    
    Set pt = ActiveSheet.PivotTables(ptName)
    
    For Each pf In pt.PivotFields
        Debug.Print pf.Name
    Next
    

    This way you'll have all the names listed in the immediate view.

提交回复
热议问题