我有一个银行名称和帐户计数的数据透视表;详细数据在另一张纸上。我正在尝试为数据透视表中的每一行创建一个新工作表,其中包括详细信息,并通过银行名称为每个选项卡命名。我使用了过去使用过的宏,但无法使其正常工作。我收到运行时错误1004-无法获取PivotItem类的DataRange属性,并且我不确定如何纠正。 TIA为您提供帮助
Sub Create_Tabs_for_Each_Dept()
Dim pField As PivotField
Dim pT As PivotTable
Dim pItem As PivotItem
Dim rngData As Range
'Which pivotTable are we working with?
Set pT = Sheets("PIVOT").PivotTables(1)
Set pField = pT.PivotFields("FI Name")
Application.ScreenUpdating = False
'Loop over each dept in that field
For Each pItem In pField.PivotItems
If pItem.Visible Then
'We want to show detail on last cell, so work to get there
Set rngData = Intersect(pT.DataBodyRange, pItem.DataRange.EntireRow)
rngData.Cells(rngData.Cells.Count).ShowDetail = True
ActiveSheet.Name = Left(pItem.Name, 30)
End If
Next pItem
Application.ScreenUpdating = True
End Sub