title: VBA run macro only once
body: <p>Im running below macro when worksheet is opened. The problem is that whenever I change value in cell or perform any event the macro starts again. How to prevent it?</p>
  
  <pre><code>Private Sub Worksheet_Calculate()
  Application.EnableEvents = False
  Dim i As Long
  
  i = Application.WorksheetFunction.CountIf(Range([W2], Cells(Rows.Count,  "W").End(xlUp)), "tak")
  Worksheets("Arkusz1").Range("AZ1").Value = i
  If Worksheets("Arkusz1").Range("AZ1").Value &gt; 0 Then
  MsgBox "Sa " &amp; i &amp; " wózki do przeglądu"
  Else
  MsgBox "Nie ma wózków do przeglądu"
  End If
  Application.EnableEvents = True
  End Sub
  </code></pre>