VBA code for Iif Function to delete rows meeting certain criteria

VBA code for Iif Function to delete rows meeting certain criteria

Post by KNIGHTW2 » Tue, 30 Oct 2001 12:39:53



I'm trying to write a macro to delete all rows in a worksheet when the sum of
the values in the rows equals zero. I have a file with several tabs (one for
each department). Each row represents an account number. Each tab has all the
same account numbers. Not all of the account numbers have values. To upload the
accounts into our mainframe, I need to eliminate all the unused accounts. Hence
the need to delete rows. Any help will be appreciated.
Thanks.
Warren

 
 
 

VBA code for Iif Function to delete rows meeting certain criteria

Post by Ivar » Thu, 01 Nov 2001 12:55:11


Be aware that a procedure that deletes rows if "the sum of the values in the
rows equals zero" will also delete rows which sum to zero but which contain
non-zero values (e.g., the sum of +20 and -20 is zero).  

Select a range of cells in a single column for the rows you want to evaluate,
then run this code:

Sub DeleteZeroRows()
  Dim lastRow As Long, R As Long
  Application.ScreenUpdating = False

  lastRow = Selection.Row - 1 + Selection.Rows.Count
  For R = lastRow To Selection.Row Step -1
    If Application.Sum(Rows(R)) = 0 Then Rows(R).Delete
  Next R

End Sub

Quote:>I'm trying to write a macro to delete all rows in a worksheet when the sum of
>the values in the rows equals zero. I have a file with several tabs (one for
>each department). Each row represents an account number. Each tab has all the
>same account numbers. Not all of the account numbers have values.


 
 
 

1. VBA code to delete row based on vaule of one cell within that row?

HI!
I am writing a little macro in Excel 97 and I have hit a little block.
I am sure this is do-able, I just lack the knowledge.
I have a cell (well actually I have a worksheet full of cells, but I
think I can work out the looping from one cell to the next...) that
contains a numerical value that is either positive or negative.
If the value is 0 or negitive I want the macro to delete the entire row.
Any suggestions? Thanks in advance!

Galen

2. Cisco 827 and VLAN's

3. VBA code to delete entire row based on missing value

4. DHCP, Samba, and names...

5. Vba Code Required for Delete Entire Row

6. Problem with Cisco 761. Please help!

7. Macro to delete certain rows

8. Implementation Class Sub-Item : Mandatory or not ?

9. looking for a simple macro to delete certain rows (records)

10. VBA code automatic typesetting and show code row number

11. Can't use a custom VBA function inside VBA code

12. Deleting Every 25th Row Using VBA

13. Excel 97 - deleting rows with VBA