Sub Macro7()
With Worksheets("STG_SB_OPICS_DTL")
With .Range(.Cells(4, "D"), .Cells(.Rows.Count, "D").End(xlUp))
.AutoFilter field:=1, Criteria1:=xlFilterToday, Operator:=xlFilterDynamic
End With
End With
End Sub
Sub Macro8()
With Worksheets("STG_SB_OPICS_DTL")
With .Range(.Cells(4, "D"), .Cells(.Rows.Count, "D").End(xlUp))
.AutoFilter field:=1, Criteria1:=xlFilterTomorrow, Operator:=xlFilterDynamic
End With
End With
End Sub
Sub TodayTomorrow()
Call Macro7
Call Macro8
End Sub
嗨,原来的问题已解决 - 但我似乎无法将这两个宏合并为一个。因此,对于动态过滤器,一旦我按下今天明天的宏代码,我希望它能够排序到今天和明天的日期,而不仅仅是今天。对此有何建议?谢谢
如果您想过滤今天和明天的日期,那么您可以尝试这个。
Option Explicit
Sub Sample()
Dim ws As Worksheet
Dim lRow As Long
Dim rng As Range
Dim TodaysDate As Date
Dim TomorrowsDate As Date
'~~> Today's date
TodaysDate = Date
'~~> Tomorrow's date
TomorrowsDate = DateAdd("d", 1, Date)
'~~> Set this to the relevant worksheet
Set ws = Worksheets("STG_SB_OPICS_DTL")
With ws
'~~> Remove any existing filter
.AutoFilterMode = False
'~~> Find last row in Col D
lRow = .Range("D" & .Rows.Count).End(xlUp).Row
'~~> Identify your filter range
Set rng = .Range("D4:D" & lRow)
'~~> Filter
With rng
.AutoFilter field:=1, _
Criteria1:="=" & TodaysDate, _
Operator:=xlOr, _
Criteria2:="=" & TomorrowsDate
End With
End With
End Sub