I have a main sub that makes use of a Client
class: creates an array with 100 000
Client
s and loops over the array 100
times, each time setting a different random number to each Client
.
Sub start() Application.ScreenUpdating = False Dim i As Long Dim j As Long Dim clientsColl() As Client ReDim clientsColl(1 To 100000) As Client For j = 1 To 100000 Set clientsColl(j) = New Client clientsColl(j).setClientName = "Client_" & j Application.StatusBar = "Getting client " & j DoEvents Next Dim clientCopy As Variant For i = 1 To 100 For Each clientCopy In clientsColl clientCopy.generateRandom Next Application.StatusBar = "Calculating " & i DoEvents Next MsgBox ("done") Application.StatusBar = False Application.ScreenUpdating = True End Sub
Client
class:
Option Explicit Dim clientName As String Dim randomNumber As Double Public Sub generateRandom() randomNumber = Rnd() End Sub Public Property Get getClientName() getClientName = clientName End Property Public Property Let setClientName(value As String) clientName = value End Property
However, this code takes different times if run from different workbooks. Being run from the first workbook it takes about 35
seconds to complete, while running from the second workbook it takes about 4
minutes. What might be the reason behind this? The only difference between the workbooks I see is the first’s size is 22 Kb
, while the second’s is 6 772 Kb
.