+ Reply to Thread
Results 1 to 5 of 5

How to search within a single cell

  1. #1
    Registered User
    Join Date
    07-11-2005
    Posts
    9

    Thumbs up How to search within a single cell

    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

  2. #2
    Dave Peterson
    Guest

    Re: How to search within a single cell

    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

    Etrnal168 wrote:
    >
    > 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
    >
    > --
    > Etrnal168
    > ------------------------------------------------------------------------
    > Etrnal168's Profile: http://www.excelforum.com/member.php...o&userid=25135
    > View this thread: http://www.excelforum.com/showthread...hreadid=492343


    --

    Dave Peterson

  3. #3
    Forum Contributor
    Join Date
    06-23-2004
    Location
    Houston, TX
    Posts
    571
    Quote Originally Posted by 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
    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 ...
    BenjieLop
    Houston, TX

  4. #4
    Registered User
    Join Date
    07-11-2005
    Posts
    9
    Thank you guys sooo much!

    -Thomas

  5. #5
    Forum Contributor
    Join Date
    06-23-2004
    Location
    Houston, TX
    Posts
    571
    Quote Originally Posted by Etrnal168
    Thank you guys sooo much!

    -Thomas
    Thank you for the feedback.

    Regards.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1