【发布时间】:2015-10-07 02:08:20
【问题描述】:
我在RowFields 中有RowField.Name 的值和PivotItem.Name 的值,我想突出显示特定的单元格。但我似乎找不到一种方法可以让我遍历每个可见的 RowField。
理想情况下,我想要这样的东西:
Sub LoopThroughPivotAndFindValue()
dim pt as PivotTable, pi as PivotItem, pf as PivotField
Set pt = wb.PivotTables("PivotTableNo1")
For each pf in pt.PivotFields
For each pi in pf.PivotItems
If pf.Name = "Test" And pi.Name = "Value" Then
'Ideally here would be the output of the address within the sheet
End If
Next pi
next pf
End Sub
最终我想为数据透视表中的特定单元格着色,但我似乎找不到正确的方法。我知道没有索引属性。
有人有想法吗?
【问题讨论】:
-
如果我对您所追求的理解正确,您可以通过评估
.Visible属性来测试可见的 PivotItems。示例:If pi.Visible = True Then
标签: excel vba loops pivot pivot-table