dhancy
Board Regular
- Joined
- Jul 10, 2013
- Messages
- 125
- Office Version
- 365
- Platform
- Windows
Hello,
My goal is to find all blank cells in a column, and when I find those cells, I want to delete the entire row.
My data has two blank cells in column B.
In the code below, the first debug statement correctly recognizes the two blank cells.
However, the For loop stops after only one iteration.
Any ideas what I am missing?
Here is my code:
Thanks!
Dennis
My goal is to find all blank cells in a column, and when I find those cells, I want to delete the entire row.
My data has two blank cells in column B.
In the code below, the first debug statement correctly recognizes the two blank cells.
However, the For loop stops after only one iteration.
Any ideas what I am missing?
Here is my code:
VBA Code:
Dim lastRow As Integer
Dim rng As Range
Dim i As Integer
lastRow = Cells(Rows.Count, 2).End(xlUp).Row
i = 0
If lastRow > 2 Then
Set rng = ActiveSheet.Range("B3:B" & lastRow)
Debug.Print "Number of empty cells: " & rng.SpecialCells(xlCellTypeBlanks).Count
For Each rw In rng.SpecialCells(xlCellTypeBlanks).Cells
Rows(rw.Row).Delete shift:=xlUp
i = 1 + i
Next rw
Debug.Print "Number of empty rows deleted: " & i
End If
Thanks!
Dennis