title: Macro to Run When New Row Added to Table Excel VBA
body: <p>I am trying to get my macro to run only when my table has a new row added.
  On the sheet that has the table, I have included this code:</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
      'This module verifies row numbers in the database by matching them to the opportunities in the Projects
      'worksheet. It then assigns row numbers in the Projects worksheet.
  
      Dim Records As Range
  
      Set Records = Range("Records")
      If Not Application.Intersect(Records, Range(Target.Address)) Is Nothing Then
             Call FindRow       
      End If        
  End Sub
  </code></pre>
  
  <p>And this is the <code>FindRow</code> code:</p>
  
  <pre><code>Sub FindRow()
      'This module verifies row numbers in the database by matching them to the opportunities in the Projects
      'worksheet. It then assigns row numbers in the Projects worksheet.
  
      Application.ScreenUpdating = False
      Dim LastRow As Long
      LastRow = Sheets("Projects").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
  
      Dim rng As Range
      Dim foundRng As Range
      For Each rng In Sheets("Projects").Range("B2:B" &amp; LastRow)
          Set foundRng = Sheets("Database").Range("C:C").Find(rng, LookIn:=xlValues, lookat:=xlWhole)
          If Not foundRng Is Nothing Then
              rng.Offset(0, -1) = foundRng.Row
          End If
      Next rng
      Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
  <p>I end up getting an <strong>Application defined or object defined</strong> error on the <code>LastRow = Sheets("Projects")...</code> line.<br>
  This is particularly odd as the code never used to give me any sort of error in the past.</p>
  
  <p>Can I please get some help?
  Records is the table being targeted.
  Database is a table on another sheet where the macro finds what row the record is located on.
  Also, should I be using <code>Worksheet_TableUpdate</code> instead of <code>Worksheet_Change</code>?
  See pictures for example:</p>
  
  <p>Records table example <img src="https://i.stack.imgur.com/pPceP.png" alt=""></p>
  
  <p>Database table example <img src="https://i.stack.imgur.com/YoWKr.png" alt=""></p>