Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Text "comparison" operator for "contains" used in an "IF" Function | Excel Worksheet Functions | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
Working out age from "Day" "Month" "Year" | Excel Worksheet Functions | |||
Insert "-" in text "1234567890" to have a output like this"123-456-7890" | Excel Discussion (Misc queries) | |||
How do I split "A1B2" into "A1" and "B2" using text to column fun. | Excel Programming |