Search for a string sequence in a cell

  • Thread starter Thread starter CLS
  • Start date Start date
C

CLS

Hi All,

Is there a way to search a cell for a chunk of text? with VBA
ex
look for here in "Hi There" since it is there highlight that cell.

I can only seem to get exact matches

Thanks
Chad
 
Hi Chad,

Not sure the entire context of what you are dealing with, but you can use
the InStr function to do this. Syntax is as follows ...

Instr(1, LookAt, LookFor)

It will return a whole number (starting position) of matched text. If no
match is found, a 0 value is returned. You can test for a cell value like
this ....

If InStr(1, Range("A1"), "Hello") > 0 Then Msgbox "Was found in A1."
 
Record a Macro doing a "Find" (Edit -> Find or Ctrl + F). Look at the results
and make any modifications you may need... If something still is not working
post a reply back with the code and we can look at it for you...

HTH
 
Another method that works well is using AutoFilter for your group and then
processing with SpecialCells. Very quick, very easy - once you get the hang
of it.

And I agree with Jim, the Find method is very, very fast.

You would get more results and a better solution if you posted your entire
quandry.
 

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