这是一个宏,用于检查行是否超过30分钟,如果不是,则清除它们。 我想改变:
Loop Until > Lastrow
反而只循环直到它到达现在的30分钟内的第一行(以减少机器挣扎时的计算量)。我尝试过各种变体:
Loop Until .Cells(i, "A") > TimeLimit
但没有运气。任何帮助非常感谢! 上下文:
Lastrow = Range("A1").SpecialCells(xlCellTypeLastCell).row
With ws1
i = 1
TimeLimit = Time - TimeSerial(0, 30, 0)
Do
If .Cells(i, "A") < TimeLimit Then
.Cells(i, "A").EntireRow.ClearContents
End If
i = i + 1
Loop Until i > Lastrow
End With
End Sub
以下是需要进入的计时器代码:
Sub Update()
With Sheets("DATA")
rw = .Cells(.rows.Count, 1).End(xlUp).row + 1
.Range(.Cells(rw, 1), .Cells(rw, 6342)).value = Sheets("DATA").Range("A7:IJZ7").value
End With
Application.OnTime Now + TimeSerial(0, 0, 1), "update"
End Sub
答案 0 :(得分:0)
试试这个:
Option Explicit
Sub Clear()
Dim wb As Workbook
Dim ws1 As Worksheet
Dim Lastrow As Long
Dim i As Long
Dim TimeLimit As Date, ChkTIme As Date
Set wb = ThisWorkbook
Set ws1 = wb.Sheets("Sheet1")
Lastrow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
TimeLimit = Time - TimeSerial(0, 30, 0)
For i = 10 To Lastrow 'Since your data starts from row 10
ChkTIme = CDate(ws1.Range("A" & i).Value)
If ChkTIme < TimeLimit Then
ws1.Rows(i).EntireRow.ClearContents
Else: End If
Next i
End Sub
将col A格式化为时间格式也不错。