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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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