How to search within a single cell

E

Etrnal168

Hey guys, first of all, thanks for reading.

I want to be able to search for a string in a cell. For example,

The content and location of the cell is 'Storage(PCI-X)' and
cells(1,1)

and I would like to search to see if the content contains PCI-X

can I do

with .range(cells(1,1))
set c = .find('PCI-X', LookIn:=xlValues, lookat:=xlWhole)

if c = true
blahblah
else
blah blah


Thanks!

-Tom
 
D

Dave Peterson

Take a look at instr in VBA's help.

dim myStr as string
mystr = Worksheets("sheet1").Range("A1").Value
If InStr(1, mystr, "PCI-X", vbTextCompare) > 0 Then
'found it
Else
'nope
end if
 
B

BenjieLop

Etrnal168 said:
Hey guys, first of all, thanks for reading.

I want to be able to search for a string in a cell. For example,

The content and location of the cell is 'Storage(PCI-X)' and
cells(1,1)

and I would like to search to see if the content contains PCI-X

can I do

with .range(cells(1,1))
set c = .find('PCI-X', LookIn:=xlValues, lookat:=xlWhole)

if c = true
blahblah
else
blah blah


Thanks!

-Tom

The formula

=NOT(ISERROR(SEARCH(\"PCI-X\",A1)

will let you know if the string "PCI-X" is in Cell A1.

From here, you can use "if c = true, blahblah else blah blah" but you
have to convert it to the ff Excel syntax, i.e.,

=if(condition or argument,value if argument is true,value if argument
is false)

Hope this helps ...
 

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

Top