简体   繁体   English

在Excel中过滤数据透视

[英]Filter Pivot in Excel

I have a problem with this filter if I set the regional language format to to English (United Kingdom), it works well if I use English (Unites States). 如果将区域语言格式设置为英语(英国),则此过滤器会出现问题,如果使用英语(美国),则效果很好。 My problem is that the filter does not make the selection of May 30 invisible, it fails in that call and goto the error section. 我的问题是筛选器不会使对5月30日的选择不可见,它在该调用中失败并转到错误部分。

http://wikisend.com/download/138750/Pivottable.xls http://wikisend.com/download/138750/Pivottable.xls

is this a known bug? 这是一个已知的错误? http://support.microsoft.com/default.aspx?scid=kb;en-us;114822&Product=xlw http://support.microsoft.com/default.aspx?scid=kb;zh-CN;114822&Product=xlw

It filters dates simular to post Filter pivottable in Excel 2003 它过滤模拟日期以在Excel 2003中过帐过滤器数据透视表

Sub Filter()
    Dim PvtItem As PivotItem
    Dim ws As Worksheet

    On Error GoTo Whoa1

    Set ws = Sheets("pivot")

    '~~> Show All
    For Each PvtItem In ws.PivotTables("PivotTable1").PivotFields("Date").PivotItems
        PvtItem.Visible = True
    Next

    On Error GoTo Whoa2 '<~~ If no match found in Pivot

    '~~> Show Only the relevant
    For Each PvtItem In ws.PivotTables("PivotTable1").PivotFields("Date").PivotItems
        If Format(PvtItem.Value, "DD/MM/YYYY") <> Format(Range("today"), "DD/MM/YYYY") Then
            PvtItem.Visible = False
        End If
    Next

    Exit Sub
Whoa1:
    MsgBox Err.Description
    Exit Sub
Whoa2:
    '~~> Show All
    For Each PvtItem In ws.PivotTables("PivotTable1").PivotFields("Date").PivotItems
        PvtItem.Visible = True
    Next
End Sub

TRIED AND TESTED IN EXCEL 2003 (With UK Settings) 在EXCEL 2003中进行了测试(使用英国设置)

Right click on the Date Field as shown in the snapshot and click on Field Settings and then click on Number . 右键单击快照中所示的“日期”字段,然后单击“ Field Settings ,然后单击“ Number Set the Date format as shown. 如图所示设置日期格式。 Now try the same code. 现在尝试相同的代码。

在此处输入图片说明

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

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