Auto filter to delete rows with zero values

Jdw5511

New Member
Joined
Jul 19, 2016
Messages
20
Hello,

I am having trouble with some code I have written in Excel 2013. I am attempting to have the filter check for zero values, and delete the resulting rows if present. If no zero values are found in the dataset, I wish for the code to continue and execute to completion. Here is what I have:

'Filter out and delete zero values


Range("A2:G2").Select
Selection.AutoFilter
Range("D2").Select
ActiveSheet.Range("A2:G" & LastRow1).AutoFilter Field:=4, Criteria1:="=0", _
Operator:=xlAnd

If Range("A3:G" & LastRow1).SpecialCells(xlCellTypeVisible).Count < 1 Then
ActiveSheet.ShowAllData

ElseIf Range("A3:G" & LastRow1).SpecialCells(xlCellTypeVisible).Count > 1 Then
EntireRow.Delete


End If

Range("E2").Select
ActiveSheet.Range("A2:G" & LastRow1).AutoFilter Field:=5, Criteria1:="=0", _
Operator:=xlAnd


If Range("A3:G" & LastRow1).SpecialCells(xlCellTypeVisible).Count < 1 Then
ActiveSheet.ShowAllData

ElseIf Range("A3:G" & LastRow1).SpecialCells(xlCellTypeVisible).Count > 1 Then
EntireRow.Delete

End If

If there are no zero values produced after the filter, I get a runtime error '1004' : No cells found.

I am stumped at this point, so if anyone can provide assistance, it would be greatly appreciated!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi

Not really looked at you code but if your code works but is only a problem if no 0 is found.

how about using at the top

on error resume next

dave
 
Upvote 0

Forum statistics

Threads
1,217,677
Messages
6,137,939
Members
450,099
Latest member
Pushbutton

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