A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Deleting rows containing zeros



 
 
Thread Tools Display Modes
  #1  
Old April 22nd, 2010, 03:08 PM posted to microsoft.public.excel.misc
Grey Old Man[_2_]
external usenet poster
 
Posts: 28
Default Deleting rows containing zeros

I am importing a variable amount (10,000+) rows of source data into an Excel
2002 worksheet. Many of the rows will contain zero in column B (total
quantity) or zero in column C (total cost) which are not required. How can I
automatically delete rows that contain zeros in BOTH columns?
The intention is then to rank the remaining data.

Thanks in anticipation.
  #2  
Old April 22nd, 2010, 03:18 PM posted to microsoft.public.excel.misc
Jim Thomlinson
external usenet poster
 
Posts: 2,641
Default Deleting rows containing zeros

There is no automatic way to delete rows. In the end that will be a process
of steps of some sort. If you are getting 10,000 + rows of source data then I
assume that it is coming from a data base of some sort. How about modifying
the query to exclude those records. If that is not possible then probably the
easiest would just to be to sort the data pulling the zeros to the top and
then delete those rows. Other possibilites would be to use an auto filter or
a pivot table...
--
HTH...

Jim Thomlinson


"Grey Old Man" wrote:

I am importing a variable amount (10,000+) rows of source data into an Excel
2002 worksheet. Many of the rows will contain zero in column B (total
quantity) or zero in column C (total cost) which are not required. How can I
automatically delete rows that contain zeros in BOTH columns?
The intention is then to rank the remaining data.

Thanks in anticipation.

  #3  
Old April 22nd, 2010, 03:29 PM posted to microsoft.public.excel.misc
Mike H
external usenet poster
 
Posts: 8,419
Default Deleting rows containing zeros

Hi,

How about a macro. Alt+F11 to open VB editor. Right click 'ThisWorkbook' and
insert module and paste the code in. Change the sheet to the correct one and
run the code. I never actually bothered to distinguish between blank cells
and zero because in this application I don't think it mmatters.

Sub delete_Me()
Dim CopyRange As Range
Dim LastRow As Long
Set sht = Sheets("Sheet1") ' change to suit
LastRow = sht.Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set MyRange = sht.Range("B1:B" & LastRow)
For Each c In MyRange
If c.Value = 0 And c.Offset(, 1).Value = 0 Then
If CopyRange Is Nothing Then
Set CopyRange = c.EntireRow
Else
Set CopyRange = Union(CopyRange, c.EntireRow)
End If
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Delete
End If
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Grey Old Man" wrote:

I am importing a variable amount (10,000+) rows of source data into an Excel
2002 worksheet. Many of the rows will contain zero in column B (total
quantity) or zero in column C (total cost) which are not required. How can I
automatically delete rows that contain zeros in BOTH columns?
The intention is then to rank the remaining data.

Thanks in anticipation.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:48 PM.


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