The blog suggested by tumchaaditya offers some excellent suggestions which are worth implementing but I doubt they will help here.
For me the key issue is that the macro slows down. Do you have commands like:
StrA = StrA & NewData
ReDim Preserve MyArray(1 To UBound(MyArray)+1)
These commands make StrA and MyArray slightly bigger. For each loop, the interpreter has to find space for the larger object, copy the data from the old object and then release the old object for garbage collection. Every time you make StrA or MyArray a little bigger, this process takes longer. I do not know why the problem is worse with Excel 2003; perhaps Excel 2007 has a better garbage collector.
If you are accumulating data from each row, something like this is much better:
Option Explicit
Type SRowDtl ' The definition of a User Type must preceed any routines
Info1 As String
Info2 As Long
Info3() As Double
End Type
Sub ProcessRows()
Dim RowDtl() as SRowDtl
Dim InxRowDtlCrntMax as Long
ReDim RowDtl(NumberOfRows)
InxRowDtlCrntMax = -1
For Each Row ....
' Store data from new row
InxRowDtlCrntMax = InxRowDtlCrntMax+1
RowDtl(InxRowDtlCrntMax).Info1 = xxx
RowDtl(InxRowDtlCrntMax).Info2 = yyy
RowDtl(InxRowDtlCrntMax).Info3(5) = zzz
Next
The syntax can look strange if you not familiar with what most languages call Structures and VBA calls User Types. But, once you are comfortable with the syntax, structures make your code much clearer and, often, much faster.
5we would have to see the code you have – datatoo – 2012-07-10T05:26:04.030
in a addition to the useful and informative answers below, are you selecting cells or ranges explicitly within your loop? This is a big performance no no NO, try just using the Range object with variables... – Our Man in Bananas – 2013-07-09T15:43:51.847
have you considered copying the sheet data to an array and working on it in memory? – Our Man in Bananas – 2013-07-09T15:44:18.630