vba Excel 数据透视表 - 日期范围筛选器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12532393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:48:46  来源:igfitidea点击:

Excel Pivot Table - Date Range Filter

excelvba

提问by kevinw690

I'm pretty new to Excel. I've created a pivot table and everything works how I want it to except for one thing, the date filter. By default by using the report filter, all of the dates pulled from my spreadsheet are in the dropdown list and they have to be checked individually to filter the table.

我对 Excel 很陌生。我创建了一个数据透视表,除了日期过滤器之外,一切都按照我想要的方式工作。默认情况下,通过使用报告过滤器,从我的电子表格中提取的所有日期都在下拉列表中,必须单独检查它们以过滤表格。

I was wondering if there is a work around to be able to filter the table using a date range, exactly how it can be done using the date filter in the spreadsheet. Why I want to be able to do is filter my pivot table by month rather than having to manually select all of the dates in the given month. Can this be accomplished using VBA?

我想知道是否有解决方法可以使用日期范围过滤表格,究竟如何使用电子表格中的日期过滤器来完成。为什么我希望能够按月过滤我的数据透视表,而不必手动选择给定月份中的所有日期。这可以使用VBA来完成吗?

回答by kevinw690

I was able to get this done without writing any code. It turned out to be quite simple. In order to get more functionality out of my date filter, I temporarily moved the date field from the report filter to the row labels. From here I grouped the date field by months and then just moved it back over to the report filter.

我能够在不编写任何代码的情况下完成这项工作。结果很简单。为了从我的日期过滤器中获得更多功能,我临时将日期字段从报告过滤器移到了行标签。从这里开始,我将日期字段按月分组,然后将其移回报告过滤器。

回答by Stepan1010

Excel has pretty robust built in date filter options on pivot tables(which version of excel are you using):

Excel 在数据透视表上具有非常强大的内置日期过滤器选项(您使用的是哪个版本的 excel):

PivotTableDateFilters

数据透视表日期过滤器

Good Luck.

祝你好运。

EDIT:

编辑:

Make your pivot table dynamic. This macro will update your pivot table:

使您的数据透视表动态化。此宏将更新您的数据透视表:

Sub UpdatePivotTable()
    Sheets(1).PivotTables(1).RefreshTable
End Sub

You can edit/sort/filter your initial data however you want.

您可以根据需要编辑/排序/过滤初始数据。

EDIT2:So you might be able to make use of something like this - then you can just autofill x's into the dates that you want - and then run the pivot table update macro: Custom Report Filter1

EDIT2:所以你可能可以使用这样的东西 - 然后你可以将 x 自动填充到你想要的日期中 - 然后运行数据透视表更新宏: 自定义报告过滤器1

Good Luck.

祝你好运。