VBA使用单元格值 - 时间定义数据透视表过滤器

时间:2017-05-12 08:15:14

标签: vba pivot-table

每当我更新控件框中的数据时,我都会尝试使用vba来定义数据透视表磁贴日期范围。

P1

但是,它仅在我将12:00放在控制箱中时才有效,而不是任何其他时间。

p2

任何人都知道为什么?是因为数据类型被定义了吗?我已经尝试过string / string / single / double,甚至试图在控制盒中转换数据类型或更改数据源中的数据类型,这些似乎都没有起作用。有什么帮助吗?

提前谢谢。

Dim UpperTime As Date
Dim LowerTime As Date
Dim KeyCells As Range
Set KeyCells = Range("A1:C5")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
       Is Nothing Then
       UpperTime = Range("C4").ValueLowerTime = Range("C5").Value
ActiveSheet.PivotTables(1).PivotFields("Sched Start Time"). _ClearLabelFilters
ActiveSheet.PivotTables(1).PivotFields("Sched Start Time"). _
PivotFilters.Add2 Type:=xlCaptionIsBetween, Value1:=UpperTime, Value2:=LowerTime

0 个答案:

没有答案
相关问题