我想检查一个给定的日期,格式为mm / dd / yyyy hh:mm:ss是否在给定的时间间隔内。间隔由开始日期定义,格式相同,持续时间以十进制表示(半小时为0.5小时),如下例所示
Sub filter_Click()
Application.ScreenUpdating = False
Dim LastDataRow, LastDataCol, LastFilterRow, LastFilterCol, FilterStart, FilterDuration,
_FilterEnd As Long
' get boundaries
With Sheets("data")
LastDataRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastDataCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
With Sheets("filter")
LastFilterRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastFilterCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
'filter the data
lineFilter = 2
For rowFilter = 2 To LastFilterRow
FilterStart = Sheets("filter").Cells(lineFilter, 5).Value
FilterDuration = Sheets("filter").Cells(lineFilter, 6).Value
FilterEnd = FilterStart + FilterDuration / 24
For colData = 1 To LastDataCol
rowdestination = 2
colDestination = colData
If colData Mod 2 <> 0 Then
For rowData = 2 To LastDataRow
dataDate = Sheets("data").Cells(rowData, colData)
If dataDate >= FilterStart And dataDate <= FilterEnd Then
Sheets("data").Cells(rowData, colData).Copy
Sheets("filtered data").Cells(rowdestination, colDestination).PasteSpecial
Sheets("data").Cells(rowData, colData + 1).Copy
Sheets("filtered data").Cells(rowdestination, colDestination + 1).PasteSpecial
rowdestination = rowdestination + 1
End If
Next rowData
End If
Next colData
Next rowFilter
Sheets("data").Range("A1:ZZ1").Copy
Sheets("filtered data").Range("A1:ZZ1").PasteSpecial
Application.ScreenUpdating = True
End Sub
现在我希望C12中的日期在E3和F3中定义的区间内,但宏不会复制它们。
事实并非如此。