View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default Loading Excel Array from VB Array Faster

Just some ideas if you are not sure of the size of the Array.

Sub ArrayThing()
'//Small Demo...
Dim DataArray(1 To 10, 1 To 5) As Variant
Dim R As Long 'Row
Dim C As Long 'Column

Randomize
For R = 1 To UBound(DataArray, 1)
For C = 1 To UBound(DataArray, 2)
DataArray(R, C) = Rnd
Next C
Next R

Range("A1").Resize(UBound(DataArray, 1), UBound(DataArray, 2)) =
DataArray
End Sub


--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"ExcelMonkey " wrote in message
...
I just answered my own question. I replaced the offset to the named
cell within the loop with :

Range("EntireArray") = DataArray

Works fine.


Option Base 1
Sub ArrayThing()
Dim DataArray(1 To 1000, 1 To 244) As Variant
Dim StartTime As Date
Dim EndTime As Date
Dim FinalTime As Double
Dim RandomVar As Double

Application.ScreenUpdating = True
Application.Calculation = xlCalculationManual

Range("EntireArray").Clear

StartTime = Now()
For A = 1 To 1000
For B = 1 To 244
Randomize
RandomVar = Rnd()
DataArray(A, B) = RandomVar
Next B
Next A

Range("EntireArray") = DataArray

EndTime = Now()
FinalTime = EndTime - StartTime
MsgBox ("The model run was completed in " & Format(FinalTime,
"hh:mm:ss") & ".")
End Sub


---
Message posted from http://www.ExcelForum.com/