title: Excel vba: program takes a long time if status bar is renewed
body: <p>I have a program that creates <code>100 000</code> objects of class <code>Client</code>, puts them into array and then goes through that array <code>100</code> times, each time assigning each <code>Client</code> a different random number through <code>Rnd()</code> function:</p>
  
  <p>Main sub:  </p>
  
  <pre><code>Sub start()
      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_" &amp; j
  
          Application.StatusBar = "Getting client " &amp; j
  
          DoEvents
      Next
  
  
      Dim tempCount As Long
      Dim clientCopy As Variant
      For i = 1 To 100
          tempCount = 0
          For Each clientCopy In clientsColl
              tempCount = tempCount + 1
  
              clientCopy.generateRandom
  
              'Application.StatusBar = "Calculating " &amp; i &amp; ": " &amp; tempCount &amp; "/" &amp; 100000  '(1)
  
              'DoEvents
          Next
  
          Application.StatusBar = "Calculating " &amp; i
  
          DoEvents
      Next
  
      MsgBox ("done")
  End Sub
  </code></pre>
  
  <p><code>Client</code> class:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The problem is, the execution time depends on whether or not line <code>(1)</code> is commented out. If it's executed, the statusbar gets renewed, but the execution time is very slow. If it's not executed, the program gets done really fast.</p>
  
  <p>Why does this happen?</p>