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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
1,998
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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
 

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
1,998
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Code:
on error resume next
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,489
Messages
5,837,640
Members
430,506
Latest member
TonyIbbs

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
Top