数据透视表的vba案例标准

时间:2013-11-28 15:26:05

标签: excel vba pivot double-quotes

我正在尝试过滤数据透视表,它取决于用户条件,这些条件总是12个值。

要创建条件,我有一系列可能的值,以下代码创建一个新的1或0列,其中一个含义包含在过滤器中:

For i = 123 To 5 Step -1
    Cells(i, 60).Value = 0
    If Cells(i, 59).Value = Criterio Then Cells(i, 60).Value = 1
    If Cells(i, 59).Value = Criterio Then Indicador = Indicador + 1
    If Indicador > 0 And Indicador <= 12 Then Cells(i, 60).Value = 1
    If Indicador = 1 Then PivotSelection = Criterio & Chr(34)
    If Indicador > 1 And Indicador < 12 Then PivotSelection = PivotSelection & "," & Chr(34) & Cells(i, 59).Value & Chr(34)
    If Indicador = 12 Then PivotSelection = PivotSelection & "," & Chr(34) & Cells(i, 59).Value
    If Indicador > 0 Then Indicador = Indicador + 1
Next i

因此它返回一个字符串,例如:“2012.01”,“2012.02”,“2012.03”,...,“2012.12”等。

我认为最好的方法是过滤枢轴使用CASE。问题是,当我在CASE选项中使用此条件时,它不起作用:

ActiveSheet.PivotTables("Table").PivotFields("CLOSING_MONTH"). _
    CurrentPage = "(All)"
With ActiveSheet.PivotTables("Table").PivotFields("CLOSING_MONTH")
    For Each oPi In .PivotItems
        If oPi = "(blank)" Then Exit For
        Select Case oPi.Value
            Case PivotSelection
                If oPi.Visible = False Then oPi.Visible = True
            Case Else
                If oPi.Visible = True Then oPi.Visible = False
            End Select
    Next oPi
End With

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试使用此代替Select Case

If (InStr(1, PivotSelection, oPi.Value)) Then
    oPi.Visible = True
Else
    oPi.Visible = False
End If