Delete rows in ListObject

Stevenn

Active Member
Joined
Feb 8, 2012
Messages
259
I try to delete all the rows in my table. I would be preferable not to delete the entire row, but only the in the table, but I guess it's not possible. When I use the code below it does what it should but ends with an error "Run-time error '1004': Application-defined or object-defined error"

Code:
For Each objRow In ActiveSheet.ListObjects("Table1").ListRows
    
        objRow.Range.EntireRow.Delete
    
Next

I have tried MsgBox objRow.Range.EntireRow.Address, and all the rows is actually in the table.

What could be the problem? Does Excel not have some kind of a truncate table function?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi Steven,
You can insert "On Error Resume Next" to before your statement. This will suppress your error message
 
Upvote 0
Thank you.

Now I can see that not all my rows will be deleted, but when I write
Code:
MsgBox objRow.Range.EntireRow.Address
it makes a MsgBox for the exact number of rows i want to delete. I can't understand what's wrong.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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