hip2b2
Board Regular
- Joined
- May 5, 2003
- Messages
- 135
- Office Version
- 2019
- Platform
- Windows
The following VBA code is intended to delete the Rows in Sheet2 where Field 12 contains the string ABC (or ABC and anything else), this works as intended. What I have belatedly discovered is that if Field 12 does not contain any instance of ABC all the data in Sheet2 below Row 6 is deleted.
Where have I messed up?
Thanks in advance.
hip
Where have I messed up?
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:="=ABC" & strName & "*", Operator:=xlAnd '<Delete Row If Contains: ABC
.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
.AutoFilter Field:=12