![]() |
Using "Like" to match strings
Trying to match the first 3 letters of a string to a company name and can't
seem to get the syntax correct. I am using variables to do it which I assume is OK. The Company name can have spaces in it. e.g. CAD does not appear in Cadbury. Is is case sensitive? Any help or a point in the right direction would be appreciated. Best Regards Steve |
Using "Like" to match strings
Hi Steve,
you could try this: =left(yourcell,3) where yourcell is the location of the cell you want to deal with. Aran -- It wasnt Jesus it was just a fella! God Bless America! "Steve" wrote: Trying to match the first 3 letters of a string to a company name and can't seem to get the syntax correct. I am using variables to do it which I assume is OK. The Company name can have spaces in it. e.g. CAD does not appear in Cadbury. Is is case sensitive? Any help or a point in the right direction would be appreciated. Best Regards Steve |
Using "Like" to match strings
Sorry Arn
I have the 3 letetrs that I am matching. The problem seems to be matching it. I have since found out that it is case sensitive. How can I get around this? This is part of the code I am using to test the match: If sExportCompName Like sTestText = True Then MsgBox "Match" GoTo Finish End If Thanks Steve "Aran Black" wrote: Hi Steve, you could try this: =left(yourcell,3) where yourcell is the location of the cell you want to deal with. Aran -- It wasnt Jesus it was just a fella! God Bless America! "Steve" wrote: Trying to match the first 3 letters of a string to a company name and can't seem to get the syntax correct. I am using variables to do it which I assume is OK. The Company name can have spaces in it. e.g. CAD does not appear in Cadbury. Is is case sensitive? Any help or a point in the right direction would be appreciated. Best Regards Steve |
Using "Like" to match strings
oh i see. I think you need to be more explicit when doing your match.
Try the InStr Function. Aran -- It wasnt Jesus it was just a fella! God Bless America! "Steve" wrote: Sorry Arn I have the 3 letetrs that I am matching. The problem seems to be matching it. I have since found out that it is case sensitive. How can I get around this? This is part of the code I am using to test the match: If sExportCompName Like sTestText = True Then MsgBox "Match" GoTo Finish End If Thanks Steve "Aran Black" wrote: Hi Steve, you could try this: =left(yourcell,3) where yourcell is the location of the cell you want to deal with. Aran -- It wasnt Jesus it was just a fella! God Bless America! "Steve" wrote: Trying to match the first 3 letters of a string to a company name and can't seem to get the syntax correct. I am using variables to do it which I assume is OK. The Company name can have spaces in it. e.g. CAD does not appear in Cadbury. Is is case sensitive? Any help or a point in the right direction would be appreciated. Best Regards Steve |
Using "Like" to match strings
First off, you don't need the =True test.... if the Like comparison matches,
it will be True and that is all the If-Then test needs (in essence, what your If-Then statement is doing is seeing if True=True, which it is). Okay, you didn't show us what you have in sTestText, so it's kind of hard to tell you what you did wrong. Let me guess though, you want to see if the first 3 letters in sExportCompName is "Cad". To answer one of your questions from your first post, yes, Like comparisons are case sensitive, but there are ways around that. Anyway, to see if the first 3 characters in sExportCompName exactly matches "Cad", you would do this... If sExportCompName Like "Cad*" Then If you wanted the test to be not case sensitive, you could do this... If sExportCompName Like "[Cc][Aa][Dd]*" Then in which case the first 3 characters could be Cad, CAD, cAd, caD, etc. and still return True for the comparison. If you did it this way... If sExportCompName Like "[Cc]ad*" then then the first 3 characters could only be Cad and cad in order for the comparison to be true. Like comparisons are quite flexible (not as flexible as Regular Expressions though), but you need to understand its syntax... the above are relative easy constructions compared to what is ultimately possible using the Like operator. Rick "Steve" wrote in message ... Sorry Arn I have the 3 letetrs that I am matching. The problem seems to be matching it. I have since found out that it is case sensitive. How can I get around this? This is part of the code I am using to test the match: If sExportCompName Like sTestText = True Then MsgBox "Match" GoTo Finish End If Thanks Steve "Aran Black" wrote: Hi Steve, you could try this: =left(yourcell,3) where yourcell is the location of the cell you want to deal with. Aran -- It wasnt Jesus it was just a fella! God Bless America! "Steve" wrote: Trying to match the first 3 letters of a string to a company name and can't seem to get the syntax correct. I am using variables to do it which I assume is OK. The Company name can have spaces in it. e.g. CAD does not appear in Cadbury. Is is case sensitive? Any help or a point in the right direction would be appreciated. Best Regards Steve |
Using "Like" to match strings
To make the default for string comparisons case insensitive, put this
statement at the top of the module: Option Compare Text Also look at Help for the StrComp function and the arguments for the Instr function. They allow you to specify the case sensitivity for that particular comparison statement-by-statement. On Fri, 2 Nov 2007 09:31:02 -0700, Steve wrote: Sorry Arn I have the 3 letetrs that I am matching. The problem seems to be matching it. I have since found out that it is case sensitive. How can I get around this? This is part of the code I am using to test the match: If sExportCompName Like sTestText = True Then MsgBox "Match" GoTo Finish End If Thanks Steve "Aran Black" wrote: Hi Steve, you could try this: =left(yourcell,3) where yourcell is the location of the cell you want to deal with. Aran -- It wasnt Jesus it was just a fella! God Bless America! "Steve" wrote: Trying to match the first 3 letters of a string to a company name and can't seem to get the syntax correct. I am using variables to do it which I assume is OK. The Company name can have spaces in it. e.g. CAD does not appear in Cadbury. Is is case sensitive? Any help or a point in the right direction would be appreciated. Best Regards Steve |
Using "Like" to match strings
PS: If you are always looking for a "begins with" match, I believe that Instr
will be faster than LIKE. On Fri, 2 Nov 2007 09:31:02 -0700, Steve wrote: Sorry Arn I have the 3 letetrs that I am matching. The problem seems to be matching it. I have since found out that it is case sensitive. How can I get around this? This is part of the code I am using to test the match: If sExportCompName Like sTestText = True Then MsgBox "Match" GoTo Finish End If Thanks Steve "Aran Black" wrote: Hi Steve, you could try this: =left(yourcell,3) where yourcell is the location of the cell you want to deal with. Aran -- It wasnt Jesus it was just a fella! God Bless America! "Steve" wrote: Trying to match the first 3 letters of a string to a company name and can't seem to get the syntax correct. I am using variables to do it which I assume is OK. The Company name can have spaces in it. e.g. CAD does not appear in Cadbury. Is is case sensitive? Any help or a point in the right direction would be appreciated. Best Regards Steve |
All times are GMT +1. The time now is 05:25 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com