View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
PaulD PaulD is offline
external usenet poster
 
Posts: 92
Default Optimizing a macro for speed- find and replace

you got way too much free time :)
Interesting to know though, every second counts...
Paul D

"shieb" wrote in message
...

I know you already have a solution, but I was bored and curious. It
appears using an array is about 70% faster than the Range.Replace
method. Here's an example using 1 sheet, a named range, 25k rows x 10
columns:

Sub ArrayTest()
Dim A As Variant
Dim R As Long
Dim C As Long
A = Sheet1.Range("DataSet").Value
For R = 1 To 25000
For C = 1 To 10
If A(R, C) = " " Then A(R, C) = ""
Next C
Next R
Sheet1.Range("DataSet").Value = A
Set A = Nothing
End Sub

This took 1.109 seconds compared to 4.110 using a .Replace method.

FYI, my guess is you have worksheet level events causing the slow down
in your orginal code. So, the Application.EnableEvents = False in
prior posts probably helped a lot.

Regards,
Steve Hieb


--
shieb
------------------------------------------------------------------------
shieb's Profile:

http://www.excelforum.com/member.php...o&userid=16404
View this thread: http://www.excelforum.com/showthread...hreadid=277560