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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 07:05 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com