Flyingmeatball
Board Regular
- Joined
- Aug 15, 2007
- Messages
- 65
I have a for loop that goes through cells in Column A, and deletes them if they are 0 or blank. However, if i delete a cell, the next row is in effect skipped, because the cells shift up. How can I make the for loop run twice if it deleted a cell? I tried deleteloop = deleteloop -1, but that just hangs my excel and i have to break the code. Here is the code:
Sub clearblanks()
Dim lastopen As Integer
With Sheets("upload file")
lastopen = .Cells(.Rows.Count, "A").End(xlUp).Row - 19
End With
For deleteloop = 20 To 20 + lastopen
If Cells(deleteloop, 4).Text = "" Or Cells(deleteloop, 4).Value = 0 Then
Rows(deleteloop).Delete
End If
Next deleteloop
End Sub
Sub clearblanks()
Dim lastopen As Integer
With Sheets("upload file")
lastopen = .Cells(.Rows.Count, "A").End(xlUp).Row - 19
End With
For deleteloop = 20 To 20 + lastopen
If Cells(deleteloop, 4).Text = "" Or Cells(deleteloop, 4).Value = 0 Then
Rows(deleteloop).Delete
End If
Next deleteloop
End Sub