Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Delete Entire Row.

An excellent point worth noting.

My advise was more to demonstrate alternate looping, which the poster seemed
to struggle with.


"J.E. McGimpsey" wrote in message
...
Even better (at least in terms of speed) is eliminating all the
incremental deletions and deleting all the rows at once:

Public Sub Eliminate()
Const cFullName = 4
Dim rCell As Range
Dim rDelete As Range
With Worksheets(1)
For Each rCell In .Range(.Cells(1, cFullName), _
.Cells(.Rows.Count, cFullName).End(xlUp))
With rCell
If Instr(.Text, " COMPANY", vbTextCompare) < 0 Then
If rDelete Is Nothing Then
Set rDelete = .Cells
Else
Set rDelete = Union(rDelete, .Cells)
End If
End If
End With
Next rCell
End With
If Not rDelete Is Nothing Then rDelete.EntireRow.Delete
End Sub

or, if " COMPANY" is expected to occur rarely, do a .Find() loop.




In article ,
"Rob van Gelder" wrote:

Best to work from bottom to up so you don't have to deal with these

types of
issues.

If you must go from top to bottom, then this code should work:

Sub Eliminate()
Const cFullName = 4
Dim i As Long, j As Long

With Worksheets(1)
i = 2: j = .Cells(.Rows.Count, cFullName).End(xlUp).Row
Do Until i j
If InStr(1, .Cells(i, cFullName).Value, " COMPANY",
vbTextCompare) < 0 Then
.Rows(i).EntireRow.Delete
j = j - 1
Else
i = i + 1
End If
Loop
End With
End Sub



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
Delete an entire row One-Leg Excel Discussion (Misc queries) 13 November 11th 08 08:27 PM
Delete entire row if David T Excel Discussion (Misc queries) 2 December 6th 06 10:14 PM
CANNOT DELETE AN ENTIRE COLUMN ibeetb Excel Discussion (Misc queries) 4 June 23rd 06 02:55 AM
Can I delete an entire row if condition is not met? Christine Excel Worksheet Functions 8 May 4th 06 09:47 AM
Delete Entire Rows Wally Steadman[_3_] Excel Programming 2 November 20th 03 08:01 AM


All times are GMT +1. The time now is 03:38 PM.

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

About Us

"It's about Microsoft Excel"