筛选表中的日期数值。

huangapple go评论52阅读模式
英文:

filter for date values in a table

问题

I have this sub:

Sub standardfilter()
    
    Dim ws As Worksheet
    Dim tbl As ListObject
    
    Set ws = ActiveSheet
    Set tbl = ws.ListObjects("Tabelle1")
    
    tbl.Range.AutoFilter field:=2, Criteria1:=">=Date()", Operator:=xlAnd
    
    Range("Tabelle1").Sort Key1:=Range("E5"), Order1:=xlAscending, Header:=xlYes

End Sub

这是您提供的代码部分的翻译。

英文:

I have this sub:

Sub standardfilter()
    
        Dim ws As Worksheet
        Dim tbl As ListObject
        
        Set ws = ActiveSheet
        Set tbl = ws.ListObjects("Tabelle1")
        
        tbl.Range.AutoFilter field:=2, Criteria1:=">=Date()", Operator:=xlAnd
        
        Range("Tabelle1").Sort Key1:=Range("E5"), Order1:=xlAscending, Header:=xlYes
        

End Sub

which is connected to a command button which when executed should first filter for dates which are today or in the future and then filter another date column in ascending order. The problem is that there is no data shown if I only execute the first filter with Criteria1:=">=Date()" whereby there is data from today or in the future.

The excel table looks like this:
筛选表中的日期数值。

"Gremium" is the event name "Gremientermin" the event's date and "Frist" is the date for a specific work flow within the process for that event.

答案1

得分: 5

tbl.Range.AutoFilter field:=2, Criteria1:=">=" & CLng(Date), Operator:=xlAnd
英文:

Use

tbl.Range.AutoFilter field:=2, Criteria1:=">=" & CLng(Date), Operator:=xlAnd

In this case the date is converted to its numeric equivalent - which is recognized as criteria independent of the systems language

huangapple
  • 本文由 发表于 2023年5月10日 20:38:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76218528.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定