以某列值为条件删除行

刪除行在這兒應該從後向前,理由是...

Private Sub CommandButton1_Click()
Dim i&
For i = Range("A65536").End(xlUp).Row To step - 1
If Cells(i, 1).Text = "" Then Rows(i).Delete
Next i
MsgBox "恭喜恭喜, 清理完畢!"
End Sub


從前往後刪的寫法可以這樣:
Private Sub CommandButton1_Click()
Dim rw As Range, rws As Range
For Each rw In UsedRange.Rows
If rw.Cells(1, 1).Text = "" Then
If rws Is Nothing Then
Set rws = rw
Else
Set rws = Union(rws, rw)
End If
End If
Next rw
rws.Delete
MsgBox "恭喜恭喜, 清理完畢!"
End Sub
arrow
arrow
    全站熱搜

    fuzzy2007 發表在 痞客邦 留言(0) 人氣()