简体   繁体   English

无法将“透视字段”设置为“隐藏”

[英]Unable to set Pivot Field to Hidden

Hopefully this will be an easy one, but I can't find the answer to this particular scenario. 希望这将是一个简单的方法,但是我找不到针对这种特定情况的答案。 I'm using the following code to hide and unhide pivot fields based on user selections. 我正在使用以下代码根据用户选择隐藏和取消隐藏枢轴字段。 The variable fieldShow is a boolean that is true if the user wants to see that particular field, while fieldLastVal is a boolean that tells whether that field is currently showing or not. 变量fieldShow是一个布尔值,如果用户希望查看该特定字段,则为fieldLastVal ,而fieldLastVal是一个布尔值,该布尔值指示该字段当前是否在显示。

If fieldShow <> fieldLastVal Then
    If fieldShow Then
        With pt.PivotFields(fieldName)
            .Orientation = xlDataField
            .Function = xlSum
        End With
    Else
        pt.PivotFields(fieldName).Orientation = xlHidden
    End If
End If
fieldLastVal = fieldShow

The issue is on the line to hide the pivot field. 问题在于隐藏枢纽领域。 The thing is, the code executes just fine. 问题是,代码执行得很好。 No errors, no nothing. 没有错误,什么都没有。 However, it never actually hides the pivot field. 但是,它实际上不会隐藏枢轴字段。 It's still there as if nothing happened. 它仍然在那里,好像什么也没发生。 I stepped through the code, and that line definitely executes, it just has no effect whatsoever on the pivot table, and I don't understand why. 我单步执行了代码,该行肯定会执行,它对数据透视表完全没有影响,我也不明白为什么。

The line that sets a pivot field's orientation to xlDataField has the desired effect. 将枢轴字段的方向设置为xlDataField具有所需的效果。 I'm not really sure what's happening here. 我不太确定这里发生了什么。

Anythoughts? 有什么想法吗?

Changing a pivot field's Orientation to xlDataField changes its name, eg, from "My Data" to "Count of My Data". 将枢轴字段的Orientation更改为xlDataField更改其名称,例如,从“我的数据”更改为“我的数据计数”。 So if you are trying to set "Count of My Data" to hidden you might actually be acting on "My Data." 因此,如果您尝试将“我的数据计数”设置为隐藏,则实际上可能是在对“我的数据”进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM