Hello all,
I have a large data set with years of 2019, 2020, 2021, in column A.
I want to filet and delete all rows that do not have a year of 2021, so I only have 2021 showing...all other rows are deleted.
I have the following code:
This does work, however, if I do not have a year of 2019, it will fault on me. Is there a better way to filter and delete all rows other than 2021, show only 2021 is left showing?
Thanks for the help
I have a large data set with years of 2019, 2020, 2021, in column A.
I want to filet and delete all rows that do not have a year of 2021, so I only have 2021 showing...all other rows are deleted.
I have the following code:
VBA Code:
With Sheets("HV-1")
Sheets("HV-1").Select
Cells.Select
Selection.AutoFilter
With .Range("A2", .Range("A" & Rows.Count).End(xlUp))
.AutoFilter 1, "2019*"
.Offset(1).SpecialCells(xlVisible).EntireRow.Delete
.AutoFilter 1, "2020*"
.Offset(1).SpecialCells(xlVisible).EntireRow.Delete
End With
.AutoFilterMode = False
End With
This does work, however, if I do not have a year of 2019, it will fault on me. Is there a better way to filter and delete all rows other than 2021, show only 2021 is left showing?
Thanks for the help