+ Reply to Thread
Results 1 to 7 of 7

code to find text and insert

  1. #1
    Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    220

    code to find text and insert

    Hi Guys

    I have a range lets say A1:A1000 with a product description in each cell. I need acode that will look through those cells and if any of them contain the word 'hello' then the word 'goodbye' would be put into the next cell.

    For example if A1 had 'hello my name is simon' in it then after the code had run the word 'goodbye would appear in B1.

    Any help would be much appreciated.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: code to find text and insert

    Here, try this:

    =IF(ISERR(FIND("hello",A1)),"","goodbye")

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: code to find text and insert

    However, this would also write you "goodbye" if your A cell has word violonchello (I know it's violoncello but need to change it for purpose of example ).

    Or do you need to ignore that words?

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: code to find text and insert

    Also, FIND is case sensitive. If you don't want case sensitive you need:

    =IF(ISERR(SEARCH("hello",A1)),"","goodbye")

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: code to find text and insert

    If you don't mind a macro, this demo might be of interest.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    220

    Re: code to find text and insert

    awsome, thanks for the replies. Yes the macro works perfectly for what I need.

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: code to find text and insert

    Hi twofootgiant

    Glad to have helped.

    Please feel free to ask anything you need explaining.

    Regards
    Alistair

    However.

    If this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody!
    Also
    If you are satisfied by any members response to your problem please consider using the scales icon top right of thier post to show your appreciation.

+ 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