For some reason the below code is filtering on all years correctly but 2020 with the below True/False argument. As you can see from the picture, it is giving a false, but not auto filtering. Any help would be great!
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("F3:F5")) Is Nothing Then
If Target.Count > 1 Then Exit Sub
' Change "E3" to the cell the user completes the year in
Const tlbName = "Table3" 'update to name of table name on relevant sheet
Dim DateCol, MinYear, MaxYear
DateCol = "D9:D" & Range("D" & Rows.Count).End(xlUp).Row 'change to match your date column
MinYear = Year(WorksheetFunction.Min(ActiveSheet.Range(DateCol)))
MaxYear = Year(WorksheetFunction.Max(ActiveSheet.Range(DateCol)))
With ActiveSheet
If Target.Value >= MinYear And Target.Value <= MaxYear Then
.ListObjects(tlbName).Range.Columns(1).AutoFilter Field:=1, Criteria1:="TRUE"
Else
.ListObjects(tlbName).Range.Columns(1).AutoFilter Field:=1, Criteria1:="TRUE"
End If
End With
End If
End Sub
Sub GetListObjectNames()
Dim ws As Worksheet
Dim lo As ListObject
Dim rng As Range
Set ws = ActiveSheet
For Each lo In ws.ListObjects
Debug.Print lo.Name
MsgBox lo.Name
Next lo
End Sub