it's been a month since i've started studying and practicing VBA in excel and this is the first time I ask a question in this forum, so keep that in mind.
The problem is this:
- I have a sheet with 300k rows and 10 columns
- Each row is the result of a calculation made in my script
- The whole script takes 2min31s to run
- I'm using ranges and all the options to speed up (e.g. "Application.Calculation = xlManual", etc)
Is it safe to think that performing the calculations on a memory variable would be faster that using a range? I've simplified the code to use as an example:
Option 1 - this is how I'm doing right now
For i = 0 To 300000
sheet.Cells(i,1).Value = i^2
Next i
Option 2 - in my head this would run faster
For i = 0 To 300000
variable(i) = i^2
Next i
'this doesn't work but it's just to illustrate what I'm looking for
sheet.Range(Cells(1,1),Cells(300000,1)).Value = variable
Can that be done? Can we pass the values of an array to a range all at once, avoiding looping through each cell of the range?