因公司每日要固定手動存檔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
跑出來的結果是:
如果想要存檔資料的時間是 昨天的 23:01 到 今天的 23:00 就不知道要如何下指令,請IT邦的Excel大神解惑
謝謝