【发布时间】:2016-11-29 01:05:36
【问题描述】:
我从这里得到了以下代码:Looping through report filters to change visibility doesn't work,其中解决方案被标记为有效。根据我的需要修改后是这样的:
With pt.PivotFields(6)
.ClearAllFilters
If .PivotItems.Count > 0 Then
'goofy but necessary
Set firstPi = .PivotItems(1)
For Each pi In .PivotItems
If firstPi.Visible = False Then
firstPi.Visible = True
End If
'Don't loop through firstPi
If pi.Value <> firstPi.Value Then
itemValue = pt.GetPivotData("[Measures].[Nr of Cancelled]", "[Characteristics].[Reason]", pi.Name).Value
rw = rw + 1
nwSheet.Cells(rw, 1).Value = pi.Name
nwSheet.Cells(rw, 2).Value = pi.Visible
If itemValue < 2000 Then
If pi.Visible = True Then
pi.Visible = False 'Error here
End If
Else
MsgBox pi.Value
If pi.Visible = False Then
pi.Visible = True 'Error here
End If
End If
End If
Next
'Finally perform the check on the first pivot item
If firstPi > 2000 Then
firstPi.Visible = True
Else
firstPi.Visible = False
End If
End If
End With
我看到整个代码工作正常,我只遇到错误 pi.Visible = True 或 pi.Visible = False 行
我不确定我在哪里做错了代码无法正常工作。
当我在互联网上搜索解决方案时,我发现了这个链接:https://support.microsoft.com/en-us/kb/114822 其中 MS 提到 只有 可以隐藏数据透视表字段中的连续项目。 这是否意味着我表中的项目不连续?谁能帮我?我迷路了。
【问题讨论】:
-
你表中的项目是连续的吗?我怀疑 SO 上的任何人都可以回答这个问题。
-
如何判断是否连续?我不知道注册这个
-
我可以查看您的 Excel 文件吗?如果是,那么请将其上传到免费的文件共享站点并在此处共享链接。还要确保如果您有任何机密数据,则将其替换为虚拟数据。
-
嗨@SiddharthRout 感谢您的回复。但是所有文件共享站点都受到限制。我不能这样做。但是,我找到了解决任务的方法。请找到我发布的答案。
标签: excel hide pivot-table pivotitem vba