thedeadzeds
Active Member
- Joined
- Aug 16, 2011
- Messages
- 451
- Office Version
- 365
- Platform
- Windows
Guys,
I have found this code but i am getting error messages when running it.
lo.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete - this brings up and error as does ws.Activate
Thanks
I have found this code but i am getting error messages when running it.
lo.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete - this brings up and error as does ws.Activate
Thanks
Code:
[COLOR=#006CCC][FONT=Courier]Sub[/FONT][/COLOR][FONT=Courier] Delete_Rows_Based_On_Value_Table()[/FONT][FONT=Courier][COLOR=#007F00]'Apply a filter to a Table and delete visible rows[/COLOR]
[COLOR=#007F00]'Source: https://www.excelcampus.com/vba/delete-rows-cell-values/[/COLOR]
[COLOR=#006CCC]Dim[/COLOR] lo [COLOR=#006CCC]As[/COLOR] ListObject
[COLOR=#007F00]'Set reference to the sheet and Table.[/COLOR]
[COLOR=#006CCC]Set[/COLOR] lo = Sheet3.ListObjects(1)
ws.Activate
[COLOR=#007F00]'Clear any existing filters[/COLOR]
lo.AutoFilter.ShowAllData
[COLOR=#007F00]'1. Apply Filter[/COLOR]
lo.Range.AutoFilter Field:=4, Criteria1:="Product 2"
[COLOR=#007F00]'2. Delete Rows[/COLOR]
Application.DisplayAlerts = [COLOR=#006CCC]False[/COLOR]
lo.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = [COLOR=#006CCC]True[/COLOR]
[COLOR=#007F00]'3. Clear Filter[/COLOR]
lo.AutoFilter.ShowAllData
[/FONT][COLOR=#006CCC][FONT=Courier]End[/FONT][/COLOR][COLOR=#006CCC][FONT=Courier]Sub[/FONT][/COLOR]