I want to be able to delete entire rows if any cell within the selected area is blank.
I know VBA can do it. I have been able to remove rows if all cells are blank, but cannot get it to work if one cell within the row is blank. I have over 95000 rows to scan with 3 columns.
The code I used to remove rows if all cells within the row was blank is:
I found the below code that claims to do what I need, but it does not work.
I know VBA can do it. I have been able to remove rows if all cells are blank, but cannot get it to work if one cell within the row is blank. I have over 95000 rows to scan with 3 columns.
The code I used to remove rows if all cells within the row was blank is:
Code:
Sub DeleteBlankRows1()
'Deletes the entire row within the selection if the ENTIRE row contains no data.
'We use Long in case they have over 32,767 rows selected.
Dim i As Long
'We turn off calculation and screenupdating to speed up the macro.
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
'We work backwards because we are deleting rows.
For i = Selection.Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
I found the below code that claims to do what I need, but it does not work.
Code:
Sub DeleteBlankRows2()
'Deletes the entire row within the selection if _
some of the cells WITHIN THE SELECTION contain no data.
On Error Resume Next
Selection.EntireRow.SpecialCells(xlBlanks).EntireRow.Delete
On Error GoTo 0
End Sub