Dim ws As Worksheet
Set ws = Sheets("Score")
Set TestTable = ws.ListObjects("Score")
With ws
.Range(TestTable & "[Correct/Incorrect]").AutoFilter 6, "Correct"
.Range(TestTable & "[Correct/Incorrect]").Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
.AutoFilterMode = False
End With
End Sub
Sub deleteFilterdRows()
Dim ws As Worksheet
Set ws = Sheets("Score")
Dim lo as ListObject
Set lo = ws.ListObjects("Score")
lo.DataBodyRange.AutoFilter field:=lo.ListColumns("Correct/Incorrect").Index, Criteria1:="Correct"
Dim rgFiltered As Range
On Error Resume Next 'if nothing was found/filtered
With lo.Range
Set rgFiltered = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
End With
On Error GoTo 0
lo.AutoFilter.ShowAllData 'remove filter otherwise deletion is not possible
If Not rgFiltered Is Nothing Then
rgFiltered.Delete
End If
End Sub
Option Explicit
Sub DeleteListObjectRows()
' Define constants.
Const wsName As String = "Score"
Const tblName As String = "Score"
Const lcName As String = "Correct/Incorrect"
Const Criteria As String = "Correct"
' Reference the workbook, worksheet and table.
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
Dim ws As Worksheet: Set ws = wb.Worksheets(wsName)
Dim tbl As ListObject: Set tbl = ws.ListObjects(tblName)
Application.ScreenUpdating = False
Dim vrg As Range
With tbl
' Check if the autofilter arrows are turned on.
If .ShowAutoFilter Then ' autofilter arrows are turned on
' Clear any table filters.
If .AutoFilter.FilterMode Then .AutoFilter.ShowAllData
Else ' autofilter arrows are turned off
.ShowAutoFilter = True ' turn on the autofilter arrows
End If
' Reference the criteria list column ('lc').
Dim lc As ListColumn: Set lc = .ListColumns(lcName)
' Filter the table range.
.Range.AutoFilter lc.Index, Criteria
' Attempt to reference the visible range ('vrg').
On Error Resume Next
Set vrg = .DataBodyRange.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
' Clear the filter.
.AutoFilter.ShowAllData
End With
' Validate and delete the visible range.
If Not vrg Is Nothing Then vrg.Delete xlShiftUp
Application.ScreenUpdating = True
' Inform.
If Not vrg Is Nothing Then