我从这里得到了以下代码:循环通过报告过滤器来更改可见性在解决方案标记为有效的情况下不起作用。根据我的需要修改后是这样的:
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 提到只能 隐藏数据透视表字段中的连续项目。 这是否意味着我表中的项目不连续?谁能帮我?我在这里迷路了。