Excel 2007 - Deleting Rows from a Table with AutoFilter

T

TomC

Given a Table1 that looks like this:
column1 column2
1 USA
2
3 USA
4 USA
5
6 UK
7 Germany
8
9 Finland
10 Russia
11 USA
12 Japan


And using Excel 2007, I need to delete all rows who have a column2 cell who
value is blank.
Sounds simple, googled a number of examples that suggest to
AutoFilter the list with an "=" criteria to match blanks:
Then using
SpecialCells(xlCellTypeVisible).EntireRow.Delete

And this code:
Sub Macro1()
Dim table As ListObject
Set table = ActiveSheet.ListObjects("Table1")
table.Range.Select
Selection.AutoFilter Field:=2, Criteria1:="="
Selection.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End Sub

I get this error:
Run-time error '1004': Delete method of Range class failed.

Any Ideas on what I am doing wrong?
TIA
Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top