Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

?Quickest way to pass an array from VB to excel? 3

Status
Not open for further replies.

navyguy

Programmer
Aug 10, 2002
30
US
Hello folks,

I have a visual basic macro running in excel. It performs all of the calculations in about 2 seconds but takes 20 seconds to send the data to excel to update an xy plot.

I pass the info with a loop like this..

for i = 1 to 1000
Worksheets("output").Cells(i+1,1)=the_array(i)
Worksheets("output").Cells(i+1,2)=another_array(i)
Next i

Is there another way to do this that might be faster?
Is the fact that the output is linked to a xy plot what slows it down? If so, is there a way to keep the chart from updating its view until all of the data is passed?

Thanks
 
Try surrounding your code with
Code:
   Application.ScreenUpdating = False
and
Code:
   Application.ScreenUpdating = True
 
navyguy,

as long as the dimensions of a range are the same as the dimensions of your array, you can dump an array straight into excel by assigning it to that range:

Code:
Dim l_rngTest As Range
Dim the_array(1000) As String

'... code filling the array

Set l_rngTest = ThisWorkbook.Sheets(1).Range("A1:A1000")
l_rngTest = the_array

HTH

Cheers
Nikki
 
Nice tip Nikki - you could also try setting calc to manual

Application.calculation = xlmanual
code
Application.calculation = xlautomatic Rgds
Geoff

Si hoc legere scis, nimis eruditionis habes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top