Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2007

Tip: Looking for answers? Try searching our database.

If sum = 0, delete row

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TJN - 26 Jul 2005 17:34 GMT
I have a spreadsheet with amounts that start in column C and goes through
column AE (columns A & B contain an entity number and an entity name).  The
number of rows varies, but it is typically about 600 rows of data.  This data
begins on row 9.  Row 8 contains the column headers and the 1st 7 rows
contain junk that comes over from the program I download this data from.  It
can be eliminated if it helps.

Basically I am looking for a macro that steps through each row of data and
if the sum of column C through column AE = zero, I would like the entire row
to be deleted.  

Does anybody have any ideas?  I feel bad because this is the third time I
have come to this group for help.  Each time the solutions have been
terriffic.  I keep hoping I can answer a question instead of always asking,
but so far all the questions asked have been above my skill level.

Thanks,

Tim
Tom Ogilvy - 26 Jul 2005 17:55 GMT
Dim rw as Long, i as Long
rw = cells(rows.count,1).End(xlup).Row
for i = rw to 9 step -1
 if Application.Sum(Cells(rw,3).Resize(1,29)) = 0 then
    rows(rw).Delete
 end if
Next

Hopefully your data actually contains numbers and not numbers stored as
strings.
Signature

Regards,
Tom Ogilvy

> I have a spreadsheet with amounts that start in column C and goes through
> column AE (columns A & B contain an entity number and an entity name).  The
[quoted text clipped - 15 lines]
>
> Tim
TJN - 26 Jul 2005 22:28 GMT
Tom -
I punched this in and it deletes only the very last row of data (which
happens to sum to zero - I didn't test to see what happens if it doesn't sum
to zero).  I was messing around with an Offset command to move up a row after
the if..then statement, but I can't seem to get it to work.  Am I missing
something?

Thanks for your help.

Tim

> Dim rw as Long, i as Long
> rw = cells(rows.count,1).End(xlup).Row
[quoted text clipped - 30 lines]
> >
> > Tim
Tom Ogilvy - 27 Jul 2005 01:00 GMT
A couple of typos - try this which worked in my test:

Sub ABCD()
Dim rw As Long, i As Long
rw = Cells(Rows.Count, 1).End(xlUp).Row
For i = rw To 9 Step -1
 If Application.Sum(Cells(i, 3).Resize(1, 29)) = 0 Then
    Rows(i).Delete
 End If
Next

End Sub

Signature

regards,
Tom Ogilvy

> Tom -
> I punched this in and it deletes only the very last row of data (which
[quoted text clipped - 41 lines]
> > >
> > > Tim
TJN - 27 Jul 2005 20:17 GMT
Tom -

Thanks.  The macro works great.  I appreciate your help.

Tim

> A couple of typos - try this which worked in my test:
>
[quoted text clipped - 62 lines]
> > > >
> > > > Tim
ron - 30 Jan 2007 01:40 GMT
Hi TJN,

I would like to know the step-by-step to use this macro as I need it too. Do
you mind telling me? Thanks, sorry for the trouble as I am total beginner in
macros.

Sharon

> Tom -
>
[quoted text clipped - 68 lines]
> > > > >
> > > > > Tim
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.