Really slow code (just this one section)

  • Thread starter Thread starter KR
  • Start date Start date
K

KR

I pull data into an array and perform several calculations; now I just need
to dump it back into my spreadsheet. For some reason, the code below is
taking 3-4 seconds per loop (of v); each loop only has to paste 8 values in
8 cells! The rest of the code runs very, very fast, it is only this section
of code that is so slow. Any suggestions on why it might be slow, and how to
speed it up?
Thanks,
Keith
XL2003 on Win2000

<snip>
For v = 1 To LastOut 'about 3000+ rows
vt = Trim(Str(v)) 'do this conversion once, instead of with each
range assignment
Application.StatusBar = "Pasting row " & vt & " of " & Str(LastOut) 'this is
so I know how fast it is[n't] going
For PasteCol = 17 To 20
UsePasteCol = Chr(PasteCol + 64)
Sheet3.Range(UsePasteCol & vt).Value = OutArr(PasteCol, v)
Next
For PasteCol = 23 To 26
UsePasteCol = Chr(PasteCol + 64)
Sheet3.Range(UsePasteCol & vt).Value = OutArr(PasteCol, v)
Next
Next
<snip>
 
Is your calculation enabled while this code is running. if it is having to
re-calc with each loop that could account for the significant time...
 
Ah, good point- I hadn't added any formulas of note, but now that I've
turned off calculation, it is running at full speed- one of the other other
users must have added some.
Thanks!!
Keith

Jim Thomlinson said:
Is your calculation enabled while this code is running. if it is having to
re-calc with each loop that could account for the significant time...
--
HTH...

Jim Thomlinson


KR said:
I pull data into an array and perform several calculations; now I just need
to dump it back into my spreadsheet. For some reason, the code below is
taking 3-4 seconds per loop (of v); each loop only has to paste 8 values in
8 cells! The rest of the code runs very, very fast, it is only this section
of code that is so slow. Any suggestions on why it might be slow, and how to
speed it up?
Thanks,
Keith
XL2003 on Win2000

<snip>
For v = 1 To LastOut 'about 3000+ rows
vt = Trim(Str(v)) 'do this conversion once, instead of with each
range assignment
Application.StatusBar = "Pasting row " & vt & " of " & Str(LastOut) 'this is
so I know how fast it is[n't] going
For PasteCol = 17 To 20
UsePasteCol = Chr(PasteCol + 64)
Sheet3.Range(UsePasteCol & vt).Value = OutArr(PasteCol, v)
Next
For PasteCol = 23 To 26
UsePasteCol = Chr(PasteCol + 64)
Sheet3.Range(UsePasteCol & vt).Value = OutArr(PasteCol, v)
Next
Next
<snip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top