我有下面的代碼,它在列M下查找空單元。每找到一個空單元格,就會刪除整行。刪除不連續的整行時出錯
該代碼始終保留一行未刪除。
有人可以幫助確定代碼有什麼問題嗎?我懷疑在刪除一行時,單元格數量出錯了。
Private Sub CreateInvoice_Click()
Dim LastRow As Long
Dim cl As Range, rng As Range
With Sheet4
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Set rng = Sheet4.Range("M1:M" & LastRow)
For Each cl In rng
If IsEmpty(cl) Then
cl.EntireRow.Select ' MsgBox .Range("A" & cl.Row).Value & " has nothing in it"
End If
Next
End With
End Sub
哇!奇妙的論壇!多謝你的快速回應。你的代碼做到了訣竅。花了2天試圖找到解決方案。 – newbi004