VBA to Delete Unused Rows

maria90

New Member
Joined
Apr 9, 2012
Messages
38
I have a listobject which can expand in size; sometimes I add new data underneath it and sometimes I delete rows.

What is the best way to delete unused data underneath the listobject? Is it something like "delete all rows from 65553 up to listobject"? How do I do that? Will I have to loop? Currently, the table's range is from A:H and it ends in row 5605.

Thanks for your help

Maria
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I forgot to mention that I want to delete all rows, even the special ones, as
even though my listobject ends in row 5605, the last row and cell is G5800.
 
Upvote 0
I forgot to mention that I want to delete all rows, even the special ones, as
even though my listobject ends in row 5605, the last row and cell is G5800.
Hi maria90,

If we are able to define a last row based on column A then you could try the following in a COPY of your workbook:

Code:
Sub DeleteUnused()
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & LastRow, "A65553").EntireRow.Delete
End Sub
 
Upvote 0
Hello Fishboy

Unfortunately, this code doesn't work because when I press CTRL + SHIFT + END the cell is in G5800.
What causes the last cell to be in that position, even though it's empty?
 
Upvote 0
Hello Fishboy

Unfortunately, this code doesn't work because when I press CTRL + SHIFT + END the cell is in G5800.
What causes the last cell to be in that position, even though it's empty?
Hmm, unfortunately that is hard to tell without seeing the workbook. Are you able to share a copy of it with us? If so, you would need to upload a copy of it to Drop Box, One Drive, Google Drive or something similar, then share the link to it here on the forums.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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