none
Error adding row to table RRS feed

  • Question

  • I'm attempting to use a userform to add a row to a named table. The code is throwing an error when it executes that causes Excel to stop working and restart. The code is...

    Dim The_Sheet As Worksheet
    Dim table_list_object As ListObject
    Dim table_object_row As ListRow
    
    Set The_Sheet = ThisWorkbook.Sheets("Sheet1")
    Set table_list_object = The_Sheet.ListObjects(1)
    Set table_object_row = table_list_object.ListRows.Add

    The last line is the offending line.

    Any ideas what is causing such a catastrophic failure?

    Monday, April 8, 2019 12:21 PM

Answers

  • re:  error message

    The code I posted works for me in XL2010.
    There appears to be multiple reasons for the error.
    One solution I saw was to simply select a cell in the table before running the code.

    I really can't provide any help.

    Monday, April 8, 2019 9:57 PM

All replies

  • re:  add row to ListObject  (table)

     

    Sub MakeTableBigger()
     Dim RowCount As Long
     Dim OldRng As Excel.Range

     With ActiveSheet.ListObjects(1)
       Set OldRng = .Range
       RowCount = OldRng.Rows.Count
       Set OldRng = OldRng.Resize(RowCount + 1, OldRng.Columns.Count)
      .Resize OldRng
    End With
    End Sub
    '---

    Custom_Functions (19 of them) add-in
    Download from MediaFire
    http://www.mediafire.com/folder/lto3hbhyq0hcf/Documents

    Monday, April 8, 2019 2:14 PM
  • Thank you for the reply. your code is more elegant than mine, however it causes the same failure on the ".Resize OldRng" command. The error moves to quickly to get much detail, however the error code is about a 15 digit negative number.

    again this event causes excel to crash, and attempt a recovery.

    EDIT:

      The error code is...

    Run-time error -2147417348 (80010108)

    Automation Error

    The Object Invoked has disconnected from it's clients.

    Monday, April 8, 2019 4:37 PM
  • re:  error message

    The code I posted works for me in XL2010.
    There appears to be multiple reasons for the error.
    One solution I saw was to simply select a cell in the table before running the code.

    I really can't provide any help.

    Monday, April 8, 2019 9:57 PM
  • re:  error message

    The code I posted works for me in XL2010.
    There appears to be multiple reasons for the error.
    One solution I saw was to simply select a cell in the table before running the code.

    I really can't provide any help.

    So you are correct. I found copy of Excel 2010, and ran the script wit no errors. Seem MS has some work to do.
    Tuesday, April 9, 2019 4:53 PM