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 fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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