|
ponponです。
考えてやってみました。無駄な部分があるとは思いますが。。。
test1もtest2も
一度では削除できず、2度3度目で、すべて削除されます。
理由がわかりません。なぜでしょう?
dataは、H列まで入っていて、E列に日付データがあります。
Sub test1()
Dim myRng As Range
Dim r As Range
Set myRng = Range("E2", Cells(Rows.Count, 5))
For Each r In myRng
If r.Value <> "" Then
If r.Value < DateValue(Now) Then
Application.DisplayAlerts = False
r.EntireRow.Delete
Application.DisplayAlerts = True
End If
End If
Next
Sub test2()
Dim myRow As Long
Dim i As Long
Dim myRng As Range
Dim mydelRng As Range
Dim r As Range
With ActiveSheet
Application.ScreenUpdating = False
myRow = .Cells(Rows.Count, 5).End(xlUp).Row
Set myRng = .Range("A1").CurrentRegion
For i = 1 To myRow
.Cells(i, 9).Value = i
Next
myRng.Sort key1:=.Range("E1")
Set mydelRng = .Range("E1", "E" & myRow)
For Each r In mydelRng
If r.Value < DateValue(Now) Then
Application.DisplayAlerts = False
r.EntireRow.Delete
Application.DisplayAlerts = True
End If
Next
Set myRng = .Range("A1").CurrentRegion
myRng.Sort key1:=.Range("I1")
For i = 1 To myRow
.Cells(i, 9).Value = ""
Next
Application.ScreenUpdating = True
End With
End Sub
|
|