我有一段代码,其中我设置了对数据透视表对象的引用,然后更改了同一数据透视表中的数据透视表对象。进行更改后,pivotcell对象似乎已被破坏,但我不知道为什么或如何阻止这种情况发生
Sub test()
Dim pc As PivotCell
Dim pi As PivotItem
'Set pivotcell object
Set pc = ActiveCell.PivotCell
For Each pi In pc.RowItems
pi.Name = CStr(pi.Name) 'In the very first loop this destroys the pivotcell item
Next pi
pc.Range.Select 'Throws 'object required' (424) error
End Sub