我发现使用这样你的For Each
:
Public Sub Create()
Dim Range1 As Range
Dim Cell
Dim LastRow As Long
Set Range1 = Range("M1")
' assume, there is some data in the first row of your sheet
LastRow = Range1.CurrentRegion.Rows.Count
' otherwise, find last cell in column M with a value, assume before row 10000
LastRow = Range("M10000").End(xlUp).Row
' select the cells to process
Set Range1 = Range(Range1, Range1.Offset(LastRow, 0))
' process the rows
For Each Cell In Range1
If Cell.Value = "Valid" Then
Debug.Print "' delete row from at address :: " & Cell.Address
Range(Cell.Address).EntireRow.Delete
End If
Next
End Sub
不要活动单元格的工作。你没有使用你的'cell'迭代器变量,从那开始。 –
此外,我**高度**建议不循环列中的所有行。最大限度地减少范围,这将有所帮助。 – BruceWayne