I have an Excel table named Master_Table with eight columns, column D being a calculated column.
I deleted all the rows in the table except the header row and the first data row.
This code works.
Worksheets("Master List").Activate
Set tbl = ActiveSheet.ListObjects("Master_Table")
'Delete all Master_table rows except first row
With tbl
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.Delete
End If
End With
I have also written data into a .csv file in a two dimensional array, Player_array, that has 24 columns and 4100 rows.
I want to add rows and assign values to Master_Table, but the first assignment statement gives a run time error:
Object variable or with block variable not set.
num_rows = UBound(Player_array, 1) - LBound(Player_array, 1) + 1
For R = 0 To num_rows
tbl.DataBodyRange.Cells(R, tbl.ListColumns("ACBL #")).Value = Player_array(R, 1)
tbl.DataBodyRange.Cells(R, tbl.ListColumns("First Name")).Value = Player_array(R, 4)
tbl.DataBodyRange.Cells(R, tbl.ListColumns("Last Name")).Value = Player_array(R, 6)
tbl.DataBodyRange.Cells(R, tbl.ListColumns("Masterpoints")).Value = Player_array(R, 13)
tbl.DataBodyRange.Cells(R, tbl.ListColumns("Phone 1")).Value = Player_array(R, 15)
tbl.DataBodyRange.Cells(R, tbl.ListColumns("Phone 2")).Value = Player_array(R, 16)
tbl.DataBodyRange.Cells(R, tbl.ListColumns("Email")).Value = Player_array(R, 22)
tbl.ListRows.Add
Next R