Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove blank rows in table

Tags:

excel

vba

I'm trying to run a macro that selects blank cells in a table column and deletes the entire row.

The script below does everything except the deleting part, which prompts the following error:

run-time error 1004 - "Delete method of Range class failed"

I have used the following code:

Sub test()
Range("Table1[[New]]").Activate
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
End Sub
like image 253
user91240192094 Avatar asked Oct 20 '12 08:10

user91240192094


People also ask

How do I delete blank rows in a table?

There is also a very handy keyboard shortcut to delete rows (columns or cells). Press Ctrl + – on the keyboard. That's it! Our blank rows are gone now.

How do you mass delete blank rows in Excel?

To delete multiple contiguous blank rows using a keyboard shortcut: Drag across the row headings using a mouse or select the first row heading and then Shift-click the last row heading. Press Ctrl + – (minus sign at the top right of the keyboard) to delete the selected rows.


1 Answers

This One liner also would help

on error resume next 'to continue macro if no empty row is found in table .Range("Table1").Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

'this delete empty using 1st column as reference for checking blanks 'Use custom names for tables for easy manipulation in codes

like image 122
Prabhu Avatar answered Nov 15 '22 18:11

Prabhu