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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default 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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default 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

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
Sorting a text strings but omitting preceding "A" or "The" Pablo Excel Worksheet Functions 2 December 15th 09 10:10 PM
=IF function, reference problem to "text strings" in Data Validati Jim D.[_2_] Excel Discussion (Misc queries) 2 July 17th 09 08:56 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
How to replace "#N/A" w "0"when vlookup couldn't find the match? Holly Excel Discussion (Misc queries) 2 July 17th 06 11:48 PM
"Casing" the strings for smooth code running Hari[_3_] Excel Programming 2 June 16th 04 04:41 PM


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

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

About Us

"It's about Microsoft Excel"