Delete row if value in Column X is 0?

  • Thread starter Thread starter CapitolMike
  • Start date Start date
C

CapitolMike

I need to delete an entire row if the value in a certain column is 0. I
found this VBA code which will delete the row if the cell is blank.
Would someone please help me modify it to look for 0 value instead of
blank?

Thanks.


Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
 
Mike,

That's not as easy. Assuming the zero values are in column A, with a
header in row 1:

Sub DeleteZeroValueRows()
Range("A1").EntireColumn.Insert
Range("A1").Value = "Keep"
Range("A2").FormulaR1C1 = _
"=IF(RC[1]=0,""Trash"",""Keep"")"
Range("A2").Copy Range("A2:A" &
Range("A2").CurrentRegion.Rows.Count)
With Range(Range("A1"), Range("A1").End(xlDown))
.Copy
.PasteSpecial Paste:=xlValues
End With
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
Columns("A:A").Find(What:="Trash", After:=Range("A1")).Select
Range(Selection, Range("A65536").End(xlUp)).EntireRow.Delete
Range("A1").EntireColumn.Delete
End Sub

HTH,
Bernie
MS Excel MVP
 
Back
Top