簡體   English   中英

Excel VBA-如果列中的時間/日期超過6小時前移動行

[英]Excel VBA - Move rows if time/date in column is more than 6 hours ago

我不確定是否可行? 我正在嘗試將列表中過去六個小時內未觸及的項目移至新的工作表中。 如何使用公式而不是匹配文本方案復制/移動行?

到目前為止,我的代碼:

With Sheets("Scheduled")
    .Select
    Firstrow = .UsedRange.Cells(2).Offset(1, 0).Row
    Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
    For Lrow = Lastrow To Firstrow Step -1
       With .Cells(Lrow, "C")
            If Not IsError(.Value) Then
                If .Value <> "Scheduled" Then
                    'Copy all "Not Scheduled" reports to the "Tracker" sheet and remove them from "Scheduled".
                    .EntireRow.Copy Sheets("Tracker").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
                    .EntireRow.Delete
                End If
            End If
        End With
    Next Lrow
End With

這段代碼並不完全是我要討論的部分,而是我在工作簿的其他部分移動行的方式。

  1. 更改C列字母,

     With .Cells(Lrow, "C") 

    ...到具有您要檢查的datetime值的列字母。

  2. 更改,

      If Not IsError(.Value) Then 

    ... 至,

      If IsNumeric(.Value) Then 'this also moves blanks 
  3. 將比較從

      If .Value <> "Scheduled" Then 

    ... 至,

      If .Value2 < (Now - TimeSerial(6, 0, 0)) Then 
  4. 在其中更改Tracker工作表名稱,

      .EntireRow.Copy Sheets("Tracker").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) 

    ...至目標工作表的名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM