I have an initial Excel workbook with about 100 000 rows. I put those rows into array and then use that array to create Client class objects, which I add into a final array resultColl.
Function getClients(dataWorkbook As Workbook)
...
With dataWorkbook.Worksheets(globals("DATA_SHEET"))
tableArray = .Range(.Cells(firstRow, column_names), _
.Cells(lastRow, column_loss_ratio)).value
For k = LBound(tableArray) To UBound(tableArray)
Set clientCopy = New Client
clientCopy.setClientName = tableArray(k, column_names)
...
Set resultColl(k) = clientCopy
Next
End With
getClients = resultColl
End Function
Then I use that array of Clients to run simulations, which means I run a for loop N times and generate a random number for each client N times:
Sub StartDataCollect()
...
Dim clientsColl() As Client
clientsColl = getClients(dataWorkbook)
...
For simulation = 1 To globals("SIMULATION_COUNT")
For Each clientCopy In clientsColl
clientCopy.setSimulationCount = globals("SIMULATION_COUNT")
clientCopy.generateRandom
Next
Next
...
End Sub
The generateRandom function:
Public Sub generateRandom()
randomNumber = Rnd()
End Sub
So, all that happens in 1 simulation: VBA runs through an array of size 100 000, puts a Rnd() inside each Client in that array.
The problem is, one iteration takes about a minute. Given I need to run at least 5 000 of them, it's a really long time. I'm not sure how to make it faster, since it doesn't seem too complicated to me already.
clientCopy.setSimulationCount = globals("SIMULATION_COUNT")in your innermost loop? The simulation count is presumably a constant(ish), so you only need to set it once. \$\endgroup\$