View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default If .value < "some text" Then not working. Pls hlp

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

--
Regards,
Tom Ogilvy

"Bythsx-Addagio" wrote:

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