PDA

View Full Version : Removing rows based on "0" Value but keeping Headers...



itipu
06-18-2007, 03:37 AM
mdmackillop (http://www.vbaexpress.com/forum/member.php?u=87) kindly provided a code to remove rows based on "0" value.

Application.ScreenUpdating = False
With Cells
.Columns(1).AutoFilter Field:=1, Criteria1:="0"
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
.Columns(1).AutoFilterMode = False
End With
Application.ScreenUpdating = True

This works lovely, except it removes headings as well!

Headings are in A1, B1 and so on...

Thanks a lot

Mike

mdmackillop
06-18-2007, 10:21 AM
There must be a "proper" way, but as a workaround, add a sacrificial row.

With Cells
.Rows(1).Insert
.Columns(1).AutoFilter Field:=1, Criteria1:="0"
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With

mvidas
06-18-2007, 12:49 PM
You could also just change the range being looked at by the special cells to not include the first row:Application.ScreenUpdating = False
With Cells
.Columns(1).AutoFilter Field:=1, Criteria1:="0"
.Rows("2:" & .Rows.Count).SpecialCells(xlCellTypeVisible).EntireRow.Delete
.Columns(1).AutoFilterMode = False
End With
Application.ScreenUpdating = True