title: Excel VBA extend table when data added below table
body: <p>I have a table in Excel that when users add data after the table, the data doesn't belong to the table.</p>
  
  <p>I've created a code that can be executed to extend the table. The code is as follows:</p>
  
  <pre><code>Sub ExtendTableToLastRow()
  
      Sheets("Update").Select
      If ActiveSheet.FilterMode Then ActiveSheet.AutoFilter.ShowAllData
      'LastRow = Cells(Rows.Count, 1).End(xlUp).Row
      LastRow = ActiveSheet.Range("a1").Offset(ActiveSheet.Rows.Count - 1, 0).End(xlUp).Row
  
      ActiveSheet.ListObjects("TUpdate").Resize Range("$A$2:$AK$" &amp; LastRow)
      Range("A1").Select
  End Sub
  </code></pre>
  
  <p>The problem is this has to be executed manually. </p>
  
  <p>Based on the comments I've created the following code:</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
      ' Sizes the table to include all new rows
      Application.EnableEvents = False
          If ActiveSheet.FilterMode Then ActiveSheet.AutoFilter.ShowAllData
          LastRow = ActiveSheet.Range("a1").Offset(ActiveSheet.Rows.Count - 1, 0).End(xlUp).Row
          ActiveSheet.ListObjects("TUpdate").Resize Range("$A$2:$AK$" &amp; LastRow)
      Application.EnableEvents = True
  End Sub
  </code></pre>
  
  <p>But the code executes when I add a value in a cell under the table, but now when I copy a row.</p>