Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
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 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default If .value < "some text" Then not working. Pls hlp

I tried to replicate your problem. I copied and pasted your code into a
sample worksheet.

Unfortunately, the code ran perfectly.
--
Gary's Student


"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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default If .value < "some text" Then not working. Pls hlp


test
"Gary''s Student" wrote:

I tried to replicate your problem. I copied and pasted your code into a
sample worksheet.

Unfortunately, the code ran perfectly.
--
Gary's Student


"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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text "comparison" operator for "contains" used in an "IF" Function Pawaso Excel Worksheet Functions 4 April 4th 23 11:35 AM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Working out age from "Day" "Month" "Year" timmyc Excel Worksheet Functions 4 February 5th 06 03:07 PM
Insert "-" in text "1234567890" to have a output like this"123-456-7890" Alwyn Excel Discussion (Misc queries) 3 October 25th 05 11:36 PM
How do I split "A1B2" into "A1" and "B2" using text to column fun. Jennifer Excel Programming 1 February 2nd 05 10:01 PM


All times are GMT +1. The time now is 08:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"