HomePro
Board Regular
- Joined
- Aug 3, 2021
- Messages
- 157
- Office Version
- 365
- 2021
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
- 2003 or older
- Prefer Not To Say
- Platform
- Windows
- MacOS
- Mobile
- Web
How can I modify this code to work on a sheet rather than a table?
Sub Delete_Rows_Based_On_Multiple_Values()
'Apply a filter to a Table and delete visible rows
'Source: VBA Macro to Delete Rows Based on Cell Values or Conditions in Excel
Dim lo As ListObject
'Set reference to the sheet and Table.
' Set lo = Data.ListObjects(1)
lo.Parent.Activate 'Activate sheet that Table is on.
'Clear any existing filters
lo.AutoFilter.ShowAllData
'1. Apply Filter - Blanks in Product for before 2015 only
lo.Range.AutoFilter Field:=10, Criteria1:="yes"
lo.Range.AutoFilter Field:=11, Criteria1:="yes"
'2. Delete Rows
Application.DisplayAlerts = False
lo.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
'3. Clear Filter
lo.AutoFilter.ShowAllData
End Sub
Sub Delete_Rows_Based_On_Multiple_Values()
'Apply a filter to a Table and delete visible rows
'Source: VBA Macro to Delete Rows Based on Cell Values or Conditions in Excel
Dim lo As ListObject
'Set reference to the sheet and Table.
' Set lo = Data.ListObjects(1)
lo.Parent.Activate 'Activate sheet that Table is on.
'Clear any existing filters
lo.AutoFilter.ShowAllData
'1. Apply Filter - Blanks in Product for before 2015 only
lo.Range.AutoFilter Field:=10, Criteria1:="yes"
lo.Range.AutoFilter Field:=11, Criteria1:="yes"
'2. Delete Rows
Application.DisplayAlerts = False
lo.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
'3. Clear Filter
lo.AutoFilter.ShowAllData
End Sub