If .value <> "some text" Then not working. Pls hlp

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dim LastRow As Long, r As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
For r = LastRow To 1 Step -1
If UCase(Cells(r, 1).Value) <> "ABCD - SUPPLY" Then Rows(r).Delete
Next r

The above code works when the comparison text is not hyphenated. (no dash or
spaces). It seems that once I add the Hyphenation it doesn't work. I tested
with a MSGBOX to see what the UCase(Cells(r, 1).Value) was and it looked
identical but the code deleted the row anyway.

What I would really like to do is use a wild card here so the compariosn
text is just "ABCD" and a wildcard (Not sure which to use here % or *. This
way I can delete every row that does not have the prefix "ABCD" "ABCD%" or
"ABCD*"

Is this possible? Can someone please advise?

thanks,
G
 
Dim LastRow As Long, r As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
For r = LastRow To 1 Step -1
If instr(1,cells(r,1),"ABCD",vbTextCompare) _
<> 1 Then Rows(r).Delete
Next r
 
I tried to replicate your problem. I copied and pasted your code into a
sample worksheet.

Unfortunately, the code ran perfectly.
 
test
Gary''s Student said:
I tried to replicate your problem. I copied and pasted your code into a
sample worksheet.

Unfortunately, the code ran perfectly.
 
Back
Top