View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Deleting rows (with zeros) with a macro

Hi,

Try this

Sub DeleteRows()
Dim RowNdx As Long
Dim LastRow As Long
StartRow = 2
LastRow = ActiveSheet.UsedRange.Rows.Count
For RowNdx = LastRow To 1 Step -1
If Not Cells(RowNdx, "F").HasFormula And _
Cells(RowNdx, "F").Value = 0 Then
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub

Mike

"ToddS" wrote:

I used the macro below and it works perfectly except when I try to use it
for cells that contain formulas. Example:

Sub Delete Rows()
Dim RowNdx As Long
Dim LastRow As Long
StartRow = 2
LastRow = ActiveSheet.UsedRange.Rows.Count
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "F").Value = "0" Then
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub

My questions is, can I somehow modify this macro to recognize a zero value
when that value is not "hard coded" in the cell but populated via a formula?