Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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? |
#2
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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? |
#3
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Hi,
maybe I got it the wrong way around, use this if you want to delete formula that evaluate as zero 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 Cells(RowNdx, "F").HasFormula And _ Cells(RowNdx, "F").Value = 0 Then Rows(RowNdx).Delete End If Next RowNdx End Sub Mike "Mike H" wrote: 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? |
#4
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
PERFECT!!! Thank you VERY MUCH!!! (It was your second response that I
needed - thanks also for catching that) "Mike H" wrote: Hi, maybe I got it the wrong way around, use this if you want to delete formula that evaluate as zero 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 Cells(RowNdx, "F").HasFormula And _ Cells(RowNdx, "F").Value = 0 Then Rows(RowNdx).Delete End If Next RowNdx End Sub Mike "Mike H" wrote: 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? |
#5
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Glad I could help
"ToddS" wrote: PERFECT!!! Thank you VERY MUCH!!! (It was your second response that I needed - thanks also for catching that) "Mike H" wrote: Hi, maybe I got it the wrong way around, use this if you want to delete formula that evaluate as zero 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 Cells(RowNdx, "F").HasFormula And _ Cells(RowNdx, "F").Value = 0 Then Rows(RowNdx).Delete End If Next RowNdx End Sub Mike "Mike H" wrote: 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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Deleting rows (with zeros) with a macro | Excel Worksheet Functions | |||
Macro for deleting rows and serialising the remaing rows | Links and Linking in Excel | |||
Macro for deleting rows and serialising the remaing rows | Setting up and Configuration of Excel | |||
Macro for deleting rows and serialising the remaing rows | Excel Worksheet Functions | |||
Deleting rows with macro | Excel Worksheet Functions |