I am using the following code to clear a table.
after clearing the table I use the built in entry form to add data to the table and get the error 91.
If I enter some data in the first row of the table, the form works well.
so I tried to enter a 1 in the table after clearing and I get the same error 91. (the line that is bolded)
Sub Clear_Table_Content()
Dim teamroster As ListObject
Worksheets("sheet1").Activate
Set teamroster = ActiveSheet.ListObjects("TeamRoster")
'Define Sheet and table name
With teamroster
'Check If any data exists in the table
If Not .DataBodyRange Is Nothing Then
'Clear Content from the table
.DataBodyRange.Rows.Delete
.DataBodyRange.Range("a1") = 1
End If
End With
'VBA Clear Table Content
end sub
The following code is used to open the built in form in excel 365
Sub openform()
'
' Macro1 Macro
'
Dim lastrow As Long
Dim teamroster As ListObject
Worksheets("sheet1").Activate
Set teamroster = ActiveSheet.ListObjects("TeamRoster")
'Debug.Print teamroster.Rows.Address
' TeamRoster.Range("A"&).Select
lastrow = teamroster.DataBodyRange.Rows.Count
End Sub
after clearing the table I use the built in entry form to add data to the table and get the error 91.
If I enter some data in the first row of the table, the form works well.
so I tried to enter a 1 in the table after clearing and I get the same error 91. (the line that is bolded)
Sub Clear_Table_Content()
Dim teamroster As ListObject
Worksheets("sheet1").Activate
Set teamroster = ActiveSheet.ListObjects("TeamRoster")
'Define Sheet and table name
With teamroster
'Check If any data exists in the table
If Not .DataBodyRange Is Nothing Then
'Clear Content from the table
.DataBodyRange.Rows.Delete
.DataBodyRange.Range("a1") = 1
End If
End With
'VBA Clear Table Content
end sub
The following code is used to open the built in form in excel 365
Sub openform()
'
' Macro1 Macro
'
Dim lastrow As Long
Dim teamroster As ListObject
Worksheets("sheet1").Activate
Set teamroster = ActiveSheet.ListObjects("TeamRoster")
'Debug.Print teamroster.Rows.Address
' TeamRoster.Range("A"&).Select
lastrow = teamroster.DataBodyRange.Rows.Count
End Sub