Copy data from a table into an empty table

taleb

New Member
Joined
Sep 12, 2008
Messages
10
Hi,
I have a problem that I need to delete the table records before I paste data into it. The problem is once I delete all the records, Excel VBA (BUG?) will not recognize it as a ListObject. Does anyone know a workaround?

This code:
Sheet111.ListObjects("Target_Table_name").DataBodyRange.PasteSpecial xlPasteValues

will give this error:
Run-time error '91':

Object variable or with block variable not set

It works fine if the table contains records.

Any suggestions?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
That error occurs when DataBodyRange is Nothing, meaning there are no data rows in the table. Try this:

Code:
    With Sheet111.ListObjects("Target_Table_name")
        If Not .DataBodyRange Is Nothing Then .DataBodyRange.PasteSpecial xlPasteValues
    End With
Post your complete code if you need more help.
 
Upvote 0
Have you tried this?

Rich (BB code):
Sheet111.ListObjects("Target_Table_name").Range.Offset(1,0).PasteSpecial xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top