开发者

does size of excel workbook matters running a vba code?

Does the size of excel workbook effect the running of a VBA code? I have written a VBA code into a excel workboo开发者_JS百科k whose size is 200 MB.The excel workbook has the browse button and these browse button picks another Excel file and performs operations and write backs some of the needed contents to the 200 MB size file. But these operation is too slow taking 8 to 13 min. These excel workbook contains charts, graphs and more modules and 16 sheets and pivot tables lots of stuff.(will these effect to run the vba code?)

But the same code I have written to another new excel workbook which is of size 200KB with the same browse button and all that stuff and here it took 4 seconds to finish. I wonder whats going wrong. Using for loops is harmful for a big file but I cannot perform my operation using without a loop in my code.If for loop is harmful then it should even effect 200KB size but no danger with that! what I have to do now?


Make sure you have used Application.ScreenUpdating=False and Application.Calculation=xlManual before the code that writes to the workbook. (Then reset them at the end).

Also there is a big overhead on each read and write to a Range, so its usually much faster to read a large block of data into a variant.

Dim vArr as Variant
vArr=Worksheets("Sheet1").Range("A1:Z9999").Value2

'Manipulate the resulting array.
For j = LBound(vArr) To UBound(vArr)
   For k = LBound(vArr,2) To UBound(vArr,2)
      vArr(j,k)=vArr(j,k)*2
   Next k
Next j

'And then write it back to its destination.
Worksheets("Sheet2").Range("A1:Z9999")=vArr


Even the mere action of reading and/or writing the file takes a significant amount of time in such a large file, many intermediate operations may be affected as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜