title: Adding new row in excel using macro (button)
body: <p>I am completely new to macros/VBA. All I am trying to do is to create a button which should add new row. I also want to add data to the new row when the row is created using the button.
  I copied the code from somewhere and I works fine there but when I try to run it, it gives me error = "Method 'Range' of object '_Worksheet' failed"
  I believe it is due to the code line:</p>
  
  <pre><code>last_row_with_data = the_sheet.Range(A65536).End(x1Up).Row
  </code></pre>
  
  <p>The person has done it using simple sub/method but I am doing it with a button</p>
  
  <p>Full code is below:</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  
  Dim the_sheet As Worksheet
  Dim table_list_object As ListObject
  Dim table_object_row As ListRow
  Set the_sheet = Sheets("Sheet1")
  Set table_list_object = the_sheet.ListObjects(1)
  Set table_object_row = table_list_object.ListRows.Add
  
  table_object_row.Range(1, 1).Value = "12324"
  
  last_row_with_data = the_sheet.Range(A65536).End(x1Up).Row
  
  the_sheet.Range("B" &amp; last_row_with_data) = "Title Name"
  the_sheet.Range("C" &amp; last_row_with_data) = "Ref Number"
  
  End Sub
  </code></pre>
  
  <p>I don't know whats wrong with code because I am completely new to macros. Anyone please correct the error?</p>