I have an VBA application that I've built within an .xlsm file. The following code is giving me an ongoing headache in that after it's been invoke a couple of time (or a dozen times--there's no predicting), I get an error message: "method add of object listrows failed". If I debug, the problem line is the ListRows.Add line. If I continue executing the code, I get a 1004 error message related to the same line and then Excel freezes and crashes and then restarts. I'm at a loss as to what the problem could be. I have code to flush the clipboard and the FreeIt function you see below unprotects the sheet where the ListObject resides. Also, I sometimes get the error when invoking another sub the deletes lines from the ListObject. And when I've tried to workaround the Add method by simply resizing the ListObject.Range by a single row, sooner or later I get the same error message, only it's "method resize of object range failed".
I've been up and down the forums out there and can't find a satisfactory answer.
Private Sub InsertRow()
Dim RowNr As Integer
Dim b As Boolean
b = FreeIt()
If line <> -1 Then
RowNr = line
Else
RowNr = Target.Rows.Count
End If
ClearClipboard
ThisWorkbook.Worksheets("Configurator").ListObjects("Products").ListRows.Add
RevertIt (b)
End Sub
Bookmarks