VBA AutoFilter区域日期格式问题

时间:2014-10-22 01:02:14

标签: vba date format autofilter

我正在尝试使用AutoFilter根据来自DTPicker的日期值过滤掉结果。

例如,我从DTPicker1选择9月1日,如下所示:

enter image description here

然后在VBA代码中,我这样做:

Worksheets("WS_Name").Range("A5:L5").AutoFilter _
 field:=3, _
 Criteria1:=">" & DTPicker1.Value, _

然后过滤器奇怪地应用到1月9日而不是9月1日。因此,使用格式DD/MM/YYYY,它会应用于09/01/2013而不是01/09/2014

我检查了操作系统上的日历设置,并且设置正确。

enter image description here

还要确保使用DTPicker1.Value

正确格式化MsgBox DTPicker1.Value

enter image description here

那么为什么AutoFilter表现得像这样呢?如何强制它以DD/MM/YYYY

格式工作

1 个答案:

答案 0 :(得分:3)

我认为VBA only understands American Date Format

因此,请尝试将DTPicker1中的日期值转换为美国日期格式,如此。

Worksheets("WS_Name").Range("A5:L5").AutoFilter _
 field:=3, _
 Criteria1:=">" & Format(DTPicker1.Value, "mm/dd/yyyy"), _
相关问题