View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Joergen Bondesen Joergen Bondesen is offline
external usenet poster
 
Posts: 110
Default EXCEPTIONALLY SLOW LOOP ....help!!!

Hi Jason


Option Explicit

'Notice @@@.
'Test with test01, please.
'Just to ensure no probleme with your array income.

Sub test01()
Dim i As Long
Dim j As Long

For i = 1 To 35
For j = 1 To 20
Worksheets("Income") _
.Cells(20 * (i - 1) + j + 1, 200) = i * j '@@@
Next j
Next i

End Sub

' <<<<<<<<<<

Sub test02()
'Used time: 00:00:00 = less than 1 second.
Dim TimeStart As Date
Dim TimeEnd As Date
Dim timeused As Date

Dim i As Long
Dim j As Long
Dim income() As Variant


Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

TimeStart = Time

For i = 1 To 35
For j = 1 To 20
ReDim Preserve income(1 To 35, 1 To 20)
income(i, j) = Cells(i, j).Value
Next j
Next i

For i = 1 To 35
For j = 1 To 20
Worksheets("Income") _
.Cells(20 * (i - 1) + j + 1, 200) = income(i, j)
Next j
Next i

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

TimeEnd = Time

timeused = TimeEnd - TimeStart

Application.StatusBar = "Finito: " _
& Format(timeused, "hh:mm:ss")

End Sub



--
Best Regards
Joergen Bondesen


"WhytheQ" wrote in message
oups.com...
I can't see any reason why the following loop should take so long to
execute.....

For i = 1 To 35
For j = 1 To 20
Worksheets("Income").Cells(20* (i - 1) + j + 1, 200) =
income(i, j)
Next j
Next i

....the 2 dimensional array 'income' has been filled, before the above
executes, with the correct numner of elements i.e income(1 to 35,1 to
20).
It's like watching paint dry when the above executes!

Any help greatly appreciated.

Jason