Delete Table Rows

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,632
Office Version
  1. 365
Platform
  1. Windows
I am wanting to delete the visible rows in a table where a filter has been applied.

This is what I'm using at the moment
Code:
   With Sheets("Events").ListObjects("tbl_EventItems")
      .Range.AutoFilter Field:=1, Criteria1:=strEvent
   
      .DataBodyRange.SpecialCells(xlCellTypeVisible).Delete

      .Range.AutoFilter Field:=1
   End With
The problem is that this deletes the entire row and not just the table rows.

As I have a pivot table to the right of the table I need to delete just the table rows and not the entire rows.


TIA
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I don't think you can delete a row in a filtered table, so you need 2 steps, like this:
I assumed there are no blank cell in column 1 before the ClearContents part, because the last line search the blank cells in column 1 then delete the rows.

Code:
   With ActiveSheet.ListObjects("Table1")
      .Range.AutoFilter Field:=1, Criteria1:="*e*"
   
      .DataBodyRange.SpecialCells(xlCellTypeVisible).ClearContents

      .Range.AutoFilter Field:=1
      
      .DataBodyRange.Columns(1).SpecialCells(xlCellTypeBlanks).Rows.Delete
   End With
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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