Excel에서 원하지 않는 행을 삭제하는 매크로가 있습니다. 오전 9시 30 분 이전과 오후 4시 이후에 행을 삭제합니다. 어떤 이유로 인해 오전 10시에서 오전 10시 9 분, 오전 11시에서 11시 9 분, 오후 12시에서 12시 9 분, 오후 1시에서 1 시까 지의 행을 삭제합니다. 오후 2 시부 터 오후 2시 9 분, 오후 3 시부 터 오후 3시 9 시까 지엑셀 추가 행 삭제
해당 행을 삭제하지 않도록 도와주세요.
내 코드 :
Sub DeleteRows()
Dim lastRow As Long
Dim Cell As Long
Dim dt As Date
'Work with the active sheet.
With ActiveSheet
'Find the last row of your dataset.
lastRow = .Range("A:A").Find("*", searchdirection:=xlPrevious).Row
'Format your time column to a readable time.
.Columns("B").NumberFormat = "[$-F400]h:mm:ss AM/PM"
'Loop through the rows, beginning at the bottom.
For Cell = lastRow To 2 Step -1
'Piece together the date.
dt = Mid(.Cells(Cell, 1), 5, 2) & "/" & _
Mid(.Cells(Cell, 1), 7, 2) & "/" & Left(.Cells(Cell, 1), 4)
'If the date is a Sat or Sun, delete the row.
If Weekday(dt) = 1 Or Weekday(dt) = 7 Then
.Rows(Cell).EntireRow.Delete
'If the time is before 9:30am or after 4pm, delete the row.
ElseIf CInt(Hour(.Cells(Cell, 2)) & Minute(.Cells(Cell, 2))) < 930 Or _
CInt(Hour(.Cells(Cell, 2)) & Minute(.Cells(Cell, 2))) > 1600 Then
.Rows(Cell).EntireRow.Delete
End If
Next Cell
End With
MsgBox "Done!"
감사합니다. 너는 천재 야 – user1681664