+ Reply to Thread
Results 1 to 6 of 6

SUBSTITUTE nested within IF

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2010
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    5

    SUBSTITUTE nested within IF

    Hi,

    I'm trying to SUBSTITUTE one of two text values depending on what is in the cell to the left.

    Formula I've tried is:

    =IF(SEARCH("XXXX",B1),SUBSTITUTE(B1,$G$1,$H$1),(SEARCH("YYYY",B1),SUBSTITUTE(B1,$G$2,$H$2)))
    Each half works separately
    =IF(SEARCH("XXXX",B1),SUBSTITUTE(B1,$G$1,$H$1)
    or
    =IF(SEARCH("YYYY",B1),SUBSTITUTE(B1,$G$2,$H$2)
    but when I try to combine them I cannot get it to work.

    Any ideas?

    Thanks

  2. #2
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: SUBSTITUTE nested within IF

    =if(search("xxxx",b1),substitute(b1,$g$1,$h$1),if(search("yyyy",b1),substitute(b1,$g$2,$h$2),"")
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: SUBSTITUTE nested within IF

    The approach will return an error if "XXXX" is not found - you would want to encase within an appropriate handler (eg ISNUMBER)

  4. #4
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: SUBSTITUTE nested within IF

    Yes it might be better to know what is in the cells and what the strings are!

    I just provided the joining, as to better formula that wasnt asked, but with more details there may be a better way!

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: SUBSTITUTE nested within IF

    What I meant by my post was: the formula won't work / not fit for purpose
    (not that it could be improved upon)

  6. #6
    Registered User
    Join Date
    08-20-2010
    Location
    Utah
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: SUBSTITUTE nested within IF [SOLVED]

    Solved. Sorry for the delayed reply. Thanks all!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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