hip2b2
Board Regular
- Joined
- May 5, 2003
- Messages
- 135
- Office Version
- 2019
- Platform
- Windows
I previously asked this question, but unfortunately I was so clumsy in the asking that I lost control of the question. Apologies in advance.
I'm not sure how to adjust the line of code below where it deletes rows that match my criteria when filtering. There are times when I do not have records that match the criteria, i.e., with "Closed " or Open in Field 12 (Col L) and so all rows on the spreadsheet are deleted.
I hope I am clear this time and many thanks in advance.
hip
I'm not sure how to adjust the line of code below where it deletes rows that match my criteria when filtering. There are times when I do not have records that match the criteria, i.e., with "Closed " or Open in Field 12 (Col L) and so all rows on the spreadsheet are deleted.
I hope I am clear this time and many thanks in advance.
hip
VBA Code:
Set h = Sheets("For Sheet2")
If h.AutoFilterMode Then h.AutoFilterMode = False
lr = Columns("A:L").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With h.Range("A6:L" & lr)
.AutoFilter Field:=12, Criteria1:="Closed" & strName & "*", Operator:=xlAnd '<Delete Row If Contains: Closed
.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
.AutoFilter Field:=12
.AutoFilter Field:=12, Criteria1:="Open" & strName & "*", Operator:=xlAnd '<Delete Row If Contains: Open
.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
.AutoFilter Field:=12