Find Null or Zero and Eliminate Entire Row if Found

Bobaree

New Member
Joined
Aug 13, 2014
Messages
41
The following sub allows me to delete entire rows if there is a cell with no data. Can anyone tell me how to get it to delete rows if a cell contains a "0" also. In other words, the VBA code would check for both and either would result in elimination of the row. Also, I currently am using this procedure seperately for several columns (E:M). If possible, I would like to combine the 10 different Subs into one Sub. Thanks for your help.

Sub Delete_Nulls_Column_E()
Dim LR As Long
Dim r As Long
With ActiveSheet
LR = .Range("A" & .Rows.Count).End(xlUp).Row
For r = LR To 2 Step -1
With .Range("E" & r)
If .Value = "" Then
.EntireRow.Delete

End If
End With
Next r
End With
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Actual null and zero; not formulas.

Code:
Sub deleteNulls()

Dim endRow As Long


With Sheets("SHEET NAME GOES HERE") 'CHANGE ME TO YOUR SHEET NAME


    
    For y = 5 To 13 Step 1
        endRow = .Cells(Rows.Count, y).End(xlUp)
        For x = endRow To 2 Step -1
            Select Case .Cells(x, y).value
                Case "", 0
                    .Cells(x, y).EntireRow.Delete
                Case Else
            End Select
        Next x
    Next y
End With


End Sub

Try that. Maybe that will solve your issues.
 
Upvote 0
We may be getting closer. Now it's getting stuck on "endRow = .Cells(Rows.Count, y).End(xlUp)". Notice that I added an Activate statement and that it's a Workbook rather than Sheet. I don't know if that affects the code you provided or not.

Sub deleteNulls()
Workbooks("Big, Safe Dividends Data.XLS").Activate
Dim endRow As Long
With Workbooks("Big, Safe Dividends Data.XLS")
For y = 4 To 13 Step 1
endRow = .Cells(Rows.Count, y).End(xlUp)
For x = endRow To 2 Step -1
Select Case .Cells(x, y).Value
Case "", 0
.Cells(x, y).EntireRow.Delete
Case Else
End Select
Next x
Next y
End With
End Sub
 
Upvote 0
We may be getting closer. Now it's getting stuck on "endRow = .Cells(Rows.Count, y).End(xlUp)". Notice that I added an Activate statement and that it's a Workbook rather than Sheet. I don't know if that affects the code you provided or not.

Sub deleteNulls()
Workbooks("Big, Safe Dividends Data.XLS").Activate
Dim endRow As Long
With Workbooks("Big, Safe Dividends Data.XLS")
For y = 4 To 13 Step 1
endRow = .Cells(Rows.Count, y).End(xlUp)
For x = endRow To 2 Step -1
Select Case .Cells(x, y).Value
Case "", 0
.Cells(x, y).EntireRow.Delete
Case Else
End Select
Next x
Next y
End With
End Sub


How about because I'm an idiot?

Code:
[COLOR=#333333]endRow = .Cells(Rows.Count, y).End(xlUp).[U][B]ROW[/B][/U][/COLOR]

Color me embarrassed.
 
Upvote 0

Forum statistics

Threads
1,216,176
Messages
6,129,316
Members
449,501
Latest member
Amriddin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top