title: Code Runs Even When New Row was not Added to Table - Excel VBA
body: <p>My code is supposed to be a simple table length check.<br>
  If the table length increases, a macro runs.<br>
  Unfortunately, it runs when I modify any data in an existing record. <strong>But it only happens once!</strong><br>
  It occurs when I open the workbook initially and then try to modify anything in the workbook. After which, it runs as it should, only when you added a new entry.
  Sub is located on the worksheet that contains static cell <code>A1</code>. This is the problem macro. It seems to behave as if there is a difference between the number of rows and the static range. But again, only when you initially open the workbook!</p>
  
  <pre><code>Private Sub Worksheet_Calculate()
  
  
      Dim n As Long
  
      n = GetTableSize()
      If n &gt; LastRowNumber Then NewDatabaseEntry
      ' Always set LastRowNumber so that even after entries are deleted (n &lt; NumRows),
      ' adding new entries will work correctly.
      LastRowNumber = n
  
  End Sub
  </code></pre>
  
  <p>Supporting macro in a separate module:</p>
  
  <pre><code>Option Explicit
  
  Public LastRowNumber As Long
  'This will be used to monitor the number of rows in the
  'Projects worksheet. This will then be compared to the
  'Value of the formula in the TableSize worksheet.
  'The value in TableSize will have a variable 'n'.
  Public Function GetTableSize() As Long
  
    GetTableSize = Worksheets("TableSize").Range("A1").Value2
  End Function
  </code></pre>
  
  <p>This sub is located on the worksheet where the table being monitored resides:</p>
  
  <pre><code>Private Sub Workbook_Open()
  
    LastRowNumber = GetTableSize()
  End Sub
  </code></pre>
  
  <p><code>NewDatabaseEntry</code> is the module that alerted me to the fact that there was a problem as it shows a pop-up before it runs. Otherwise, I would've been unaware of there being a problem in the first place.
  Any help would be appreciated.</p>