I have a forecasting procedure that writes out 3 sets of data, with setA dependent on calculations from data in setB and setC – all with the same set of columns for years. Everything is being done via ranges and it runs slow for the relatively few hundred amounts it calculates and writes out. So I have tried to teach myself about arrays by reading other posts and watching videos. And where application meets knwledge, I am failing. For now, I believe I need to use a 1 dimensional array to write to a single row multi-column array. I would perform the calcs within the array as shown below, then write the row out, resetting the output range for each. Then when processing the next account, I would have to reset the range to write out the next row of data. Maybe a 2D array may be easier. I only hesitate on the 2D becasue I am so new to arrays, perhaps baby steps. But for now, I am finding I cannot set up a 1D array with a variable, as debug tells me it must be a constant.
Sub TestArrays()
Dim iYrCount As Variant, rg As Range, iRowCtr As Integer, iLastSourceRow As Integer, snFactor As Single
iYrCount = 30 'Hardcoded for this post. It is dynamically set earlier in the sub
iLastSourceRow = 20 'Source of account names and metadata. Again, it is hardcoded for this post.
iRowCtr = 1
Dim arr(iYrCount) As Variant, icol As Variant
Do Until iRowCtr = iLastSourceRow + 1
icol = 1
For Each icol In arr
'Do stuff...
arr(icol) = arr(icol - 1) * snFactor 'although much more complex than this.
' icol = icol + 1
Next
Set rg = ThisWorkbook.Sheets("Sheet1").Range("A" & iRowCtr)
rg = arr
Nest
iRowCtr = iRowCtr + 1
End Sub
Thanks for any help or advice.
2