iT邦幫忙

0

Excel 巨集-撈取指定的時間

  • 分享至 

  • xImage

因公司每日要固定手動存檔Audit log,覺得太麻煩所以想使用巨集來執行,資料只需要兩天所以VBA設定上是這樣做:
Dim today As Date, yesterday As Date, lastrow2 As Long, n As Long

today = Date
yesterday = today - 1

Range("V1").Value = today
Range("W1").Value = yesterday
Range("X1").Value = "UserLogging"


Dim cl As Range
With Worksheets(2).Cells

Set cl = Range("A:A").find(What:=yesterday, LookAt:=xlPart)
    If Not cl Is Nothing Then
        cl.Select
    End If
End With


Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("CUCM").Select
Range("A2").Select
ActiveSheet.Paste

lastrow2 = Cells.SpecialCells(xlCellTypeLastCell).Row

For n = lastrow2 To 2 Step -1
    If Not (Range("E" & n).Value = " UserLogging") Then
        Rows(n).Delete
    End If
Next n

跑出來的結果是:
https://ithelp.ithome.com.tw/upload/images/20230120/20150710oxGnc5X7TD.jpg

如果想要存檔資料的時間是 昨天的 23:01 到 今天的 23:00 就不知道要如何下指令,請IT邦的Excel大神解惑

謝謝

win895564 iT邦新手 1 級 ‧ 2023-01-20 17:57:54 檢舉
昨天 23:01 至今天 23:00 的時間區間: =DATE(YEAR(TODAY()), MONTH(TODAY()), DAY(TODAY())-1)+TIME(23,1,0) : DATE(YEAR(TODAY()), MONTH(TODAY()), DAY(TODAY()))+TIME(23,0,0)
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答