Instr question

  • Thread starter Thread starter Sandy H
  • Start date Start date
S

Sandy H

Hi
Can anyone tell me whether it is possible to apply more than one search
character to the Instr function. To give an example of what I mean, I want
to find either an 'A' or a '2'. Can this be done in the one instr
statement.

Thanks
Sandy
 
hi Sandy,

Sandy said:
Can anyone tell me whether it is possible to apply more than one search
character to the Instr function. To give an example of what I mean, I want
to find either an 'A' or a '2'. Can this be done in the one instr
statement.
No, but maybe is the Microsoft RegEx library of interest for you. You
can activate it in the VBA references dialog.


mfG
--> stefan <--
 
hi,
No, but maybe is the Microsoft RegEx library of interest for you. You
can activate it in the VBA references dialog.
It is called "Microsoft VBScript Regular Expressions".


mfG
--> stefan <--
 
Hi Sandy,

If you just want to know whether a string _contains_ the characters in
question, you can use the Like operator, e.g.

S = "Once upon a time"
? S Like "*[A2]*"
True

If you need to know the _position_ of the character(s) in the string, or
if you're searching for something more complicated than one of a number
of characters (e.g. an "A2" or a "B4"), the obvious ways are to use
either one call to InStr() for each character or a regular expression
engine.

There's some information about using regular expressions in VBA, and a
couple of useful functions, at
http://www.j.nurick.dial.pipex.com/Code/index.htm
 
Thanks Stefan and John. I thought that was the case.

Appreciate your help.

Sandy
John Nurick said:
Hi Sandy,

If you just want to know whether a string _contains_ the characters in
question, you can use the Like operator, e.g.

S = "Once upon a time"
? S Like "*[A2]*"
True

If you need to know the _position_ of the character(s) in the string, or
if you're searching for something more complicated than one of a number
of characters (e.g. an "A2" or a "B4"), the obvious ways are to use
either one call to InStr() for each character or a regular expression
engine.

There's some information about using regular expressions in VBA, and a
couple of useful functions, at
http://www.j.nurick.dial.pipex.com/Code/index.htm

Hi
Can anyone tell me whether it is possible to apply more than one search
character to the Instr function. To give an example of what I mean, I
want
to find either an 'A' or a '2'. Can this be done in the one instr
statement.

Thanks
Sandy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top