我有一个数据透视表,我循环并根据表中的信息填充区域。我的问题是数组仍在收集过滤掉的数据。有办法解决这个问题吗?
这是用于了解我正在做什么的代码。
Do While count < managerCount – 1
MGR = CStr(ActiveSheet.PivotTables(1).RowFields(1).PivotItems(MGRCount + 1).Value)
late = ActiveSheet.PivotTables(1).GetPivotData("Count of Action Item ID", "Mgr", MGR, "Status to Plan", "Late").Value
If late = "" Then
late = 0
End If
On Error GoTo ErrHandler
lateProjects(count, 0) = MGR
lateProjects(count, 1) = late
MGRCount = MGRCount + 1
count = count + 1
Loop
感谢您提供的任何帮助。
答案 0 :(得分:0)
PivotItems
集合包含所有项目,即使它们未显示也是如此。但是,您可以查看.Visible
!
这是完整的代码:
Dim piv As PivotTable
Dim pivItem As PivotItem
Set piv = ActiveSheet.PivotTables(1)
Do While count < managerCount - 1
Set pivItem = piv.RowFields(1).PivotItems(MGRCount + 1)
If pivItem.Visible Then
MGR = CStr(pivItem.Value)
late = piv.GetPivotData("Count of Action Item ID", "Mgr", MGR, "Status to Plan", "Late").Value
If late = "" Then
late = 0
End If
On Error GoTo ErrHandler
lateProjects(count, 0) = MGR
lateProjects(count, 1) = late
MGRCount = MGRCount + 1
End If
count = count + 1
Loop