Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 9
Default Deleting rows (with zeros) with a macro

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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
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?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Deleting rows (with zeros) with a macro

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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 9
Default Deleting rows (with zeros) with a macro

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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Deleting rows (with zeros) with a macro

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting rows (with zeros) with a macro Scott R Excel Worksheet Functions 7 April 3rd 09 06:13 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Links and Linking in Excel 1 November 13th 08 08:44 AM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Setting up and Configuration of Excel 1 November 12th 08 06:05 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Excel Worksheet Functions 1 November 12th 08 01:39 PM
Deleting rows with macro PhilScratchingmyhead Excel Worksheet Functions 2 June 29th 06 05:55 PM


All times are GMT +1. The time now is 12:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"