PC Review


Reply
Thread Tools Rate Thread

2 more forumla explanations....

 
 
scotiajoe
Guest
Posts: n/a
 
      25th Nov 2003

Range("L1").Select
count2 = 1
For count1 = 1 To 900
Range(Cells(count2, 12), Cells(count2, 12)).Select
If ActiveCell.Value <> 0 Then
count2 = count2 + 1
Else: Selection.EntireRow.Delete
count2 = count2
End If
Next


Range("M1").Select
count2 = 1
For count1 = 1 To 900
Range(Cells(count2, 13), Cells(count2, 13)).Select
If ActiveCell.Value <> 0 Then
count2 = count2 + 1
Else: Selection.EntireRow.Delete
count2 = count2
End If
Next

Thank you

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

 
Reply With Quote
 
 
 
 
J.E. McGimpsey
Guest
Posts: n/a
 
      25th Nov 2003
Both snippets are rather slow methods of deleting lines with zero in
their respective columns.

The first Selects L1, then selects the 1st row of the 12th column
(which is also L1), checks if the value is 0. If not, it selects the
cell in the next row; if it is, it deletes the row. It will cycle
900 times.

It could be much more efficiently replaced by:

Dim i As Long
For i = 900 To 1 Step -1
If Cells(i, 12).Value = 0 Then Cells(i,12).EntireRow.Delete
next i

Note that no selections are necessary. It is necessary to go from
last row to first row since XL renumbers the rows when they're
deleted, but the loop variable is not adjusted.

A bit faster, since it deletes all the rows at once (and thus
doesn't have to go from high row number to low):

Dim i As long
Dim delRange As Range
For i = 1 to 900
With Cells(i, 12)
If .Value = 0 Then
If delRange Is Nothing Then
Set delRange = .Cells
Else
Set delRange = Union(delRange, .Cells)
End If
End If
End With
Next i
If Not delRange Is Nothing Then delRange.EntireRow.Delete

If both column L and column M are to be checked, instead of doing it
sequentially, you can do it at the same time:

Dim i As Long
Dim delRange As Range
For i = 1 to 900
With Cells(i, 12)
If .Value = 0 Or (.Offset(0, 1).Value = 0) Then
If delRange Is Nothing Then
Set delRange = .Cells
Else
Set delRange = Union(delRange, .Cells)
End If
End If
End With
Next i
If Not delRange Is Nothing Then delRange.EntireRow.Delete

and if there may be more or less than 900 rows to check, you can
replace

For i = 1 to 900

with

For i = 1 to Cells(Rows.Count, 12).End(xlUp).Row

to check all rows up to the last filled row in column L.

In article <(E-Mail Removed)>,
scotiajoe <(E-Mail Removed)> wrote:

> Range("L1").Select
> count2 = 1
> For count1 = 1 To 900
> Range(Cells(count2, 12), Cells(count2, 12)).Select
> If ActiveCell.Value <> 0 Then
> count2 = count2 + 1
> Else: Selection.EntireRow.Delete
> count2 = count2
> End If
> Next
>
>
> Range("M1").Select
> count2 = 1
> For count1 = 1 To 900
> Range(Cells(count2, 13), Cells(count2, 13)).Select
> If ActiveCell.Value <> 0 Then
> count2 = count2 + 1
> Else: Selection.EntireRow.Delete
> count2 = count2
> End If
> Next

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Explanations of Errors Zygy Windows Vista General Discussion 4 29th Apr 2008 12:57 PM
3 explanations required - please help almurph@altavista.com Microsoft C# .NET 3 18th Mar 2008 04:55 PM
Technical Explanations gabriella General Discussion 4 20th Nov 2007 10:47 PM
Odd Error-Any Possible Explanations? =?Utf-8?B?RWQgQXJkemluc2tp?= Microsoft Excel Programming 3 26th Oct 2004 08:34 PM
formula explanations... scotiajoe Microsoft Excel Discussion 5 25th Nov 2003 02:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:45 PM.