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!
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!