Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default slow code needs tuning

Greetings and TIA for your time
I have a database of about 2,500 records.
I am deleting all records that have a null string (="") in field1:

with range("Field1")
for each cl in .cells
if cl = "" then cl.entirerow.delete
next
end with

This works fine but is slow.

if the cells i were looking for contained blanks, I could use:
range("Field1").specialcells(xlblanks).entirerow.d elete
which I think would be much quicker. sadly, I'm hunting for null strngs.
Any ideas on how to speed the code up?
--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default slow code needs tuning

just wondering if it's the screen updating that's a problem, too.

have you tried

Application.ScreenUpdating = False

at the beginning of the code and

Application.ScreenUpdating = True

at the end of the code


just a guess
--


Gary


"David" wrote in message
...
Greetings and TIA for your time
I have a database of about 2,500 records.
I am deleting all records that have a null string (="") in field1:

with range("Field1")
for each cl in .cells
if cl = "" then cl.entirerow.delete
next
end with

This works fine but is slow.

if the cells i were looking for contained blanks, I could use:
range("Field1").specialcells(xlblanks).entirerow.d elete
which I think would be much quicker. sadly, I'm hunting for null strngs.
Any ideas on how to speed the code up?
--
David



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default slow code needs tuning

Try the following. The only thing I did not account for is if the first
row of the range contains a blank.

Option Explicit

Sub Test()

Dim rFind As Range
Dim rTemp As Range

Set rFind = Range("Test").Find(what:="", lookat:=xlWhole)
While Not rFind Is Nothing
' Back up one row
Set rTemp = rFind.Offset(-1, 0)
rFind.EntireRow.Delete
Set rFind = Range("Test").FindNext(after:=rTemp)
Wend

End Sub



*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default slow code needs tuning


"David" wrote in message
...
Greetings and TIA for your time
I have a database of about 2,500 records.
I am deleting all records that have a null string (="") in field1:

with range("Field1")
for each cl in .cells
if cl = "" then cl.entirerow.delete
next
end with

This works fine but is slow.

if the cells i were looking for contained blanks, I could use:
range("Field1").specialcells(xlblanks).entirerow.d elete
which I think would be much quicker. sadly, I'm hunting for null strngs.
Any ideas on how to speed the code up?
--
David


Untested; but autofiltering(Field1)=VbNull deleting the resulting "visibile"
rows should speed things up??

With Range("Field1")
..AutoFilter Field:=1, Criteria1:=vbnull
..SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default slow code needs tuning

Try:
Application.ScreenUpdating = False
with range("Field1")
for each cl in .cells
if cl = "" then cl.entirerow.delete
next
end with
Application.ScreenUpdating = True





"David" wrote:

Greetings and TIA for your time
I have a database of about 2,500 records.
I am deleting all records that have a null string (="") in field1:

with range("Field1")
for each cl in .cells
if cl = "" then cl.entirerow.delete
next
end with

This works fine but is slow.

if the cells i were looking for contained blanks, I could use:
range("Field1").specialcells(xlblanks).entirerow.d elete
which I think would be much quicker. sadly, I'm hunting for null strngs.
Any ideas on how to speed the code up?
--
David



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default slow code needs tuning

Instead of using "if cl = ""...", use "if len(c)=0 ...", it is a numerical
evaluation, which is runs faster than a string evaluation. Also, turn screen
updating off:

application.screenupdating = False

'do loop here

application.screenupdating = True

Be careful about using the word "null." "Null" is a legitimate value in VB
(vbNull), whereas a zero-length string is NOT a null value.


"David" wrote:

Greetings and TIA for your time
I have a database of about 2,500 records.
I am deleting all records that have a null string (="") in field1:

with range("Field1")
for each cl in .cells
if cl = "" then cl.entirerow.delete
next
end with

This works fine but is slow.

if the cells i were looking for contained blanks, I could use:
range("Field1").specialcells(xlblanks).entirerow.d elete
which I think would be much quicker. sadly, I'm hunting for null strngs.
Any ideas on how to speed the code up?
--
David

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
help w/ fine tuning Mike New Users to Excel 1 October 19th 05 08:58 PM
SLOW Code... Ernst Guckel[_4_] Excel Programming 2 March 20th 05 10:58 AM
Slow Code Frank Kabel Excel Programming 1 July 23rd 04 09:28 AM
Is this slow code? Tom Excel Programming 4 March 3rd 04 11:18 PM
Tuning Off Toolbars Phil Hageman[_3_] Excel Programming 4 October 28th 03 09:21 PM


All times are GMT +1. The time now is 08:34 AM.

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

About Us

"It's about Microsoft Excel"