+ Reply to Thread
Results 1 to 9 of 9

Formula to replace values if another exists

  1. #1
    Forum Contributor
    Join Date
    03-26-2014
    Location
    Kentucky
    MS-Off Ver
    Excel 2013
    Posts
    128

    Formula to replace values if another exists

    So I have this formula to basically lookup the letters in column L and if certain letters exist, then change those letters to another letter.
    Here is my Formula:

    =IF(L1="A",IF(ISNUMBER(MATCH("B",$L$1:$L$200,0)),"B",L1),IF(L1="D",IF(ISNUMBER(MATCH("E",$L$1:$L$200,0)),"E",L1),IF(L1="L",IF(ISNUMBER(MATCH("L",$L$1:$L$200,0)),"O",L2),IF(L2="F",IF(ISNUMBER(MATCH("K",$L$1:$L$200,0)),"K",L1),L1))))

    For example: if column L looks like

    A
    B
    A
    E
    D

    Then it would convert the A's to B's since there is a B present and D's to E's, but if the B and E hadn't been in the equation then it would leave the A's and D's as they are. WIth this formula the output looks like:
    B
    B
    B
    E
    E

    My problem with this formula is that it only recognizes the first letter in each column. Sometimes I have multiple letters in a column and I need it to recognize them and change accordingly.
    For example:
    A
    D_B
    E

    I would like to have it change to
    B
    E_B
    E

    If anyone could help me with this problem I would be very appreciative!

    I have attached a sample workbook that may make it more clear... If a VBA code would work better then I would be open to that as well.
    Combining question.xlsx

  2. #2
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Formula to replace values if another exists

    try below in C27
    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A27,"A","B"),"D","E"),"L","O"),"F","K") then drag down or

    in C6
    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C6,"A","B"),"D","E"),"L","O"),"F","K") drag down till you have data
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    WANT TO SAY THANKS, HIT ADD REPUTATION (*) AT THE BOTTOM LEFT CORNER OF THE POST

    More we learn about excel, more it shows us, how less we know about it.

    for chemistry
    https://www.youtube.com/c/chemistrybyshivaansh

  3. #3
    Forum Contributor
    Join Date
    03-26-2014
    Location
    Kentucky
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: Formula to replace values if another exists

    That almost works but i don't want to completely replace the letter with the other, only if the other letter is also present in the array. So if "A" is present and "B" is not then keep the "A" an "A". However, only if a "B" is present then change the "A" or "A"s to "B" or "B"s. THank you for your reply.

  4. #4
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Formula to replace values if another exists

    can you explain bit more which array you are talking about is related with the content of cells

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Formula to replace values if another exists

    I looked at this too, but could not figure out what you wanted

    Can you upload a few sample answers please
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  6. #6
    Forum Contributor
    Join Date
    03-26-2014
    Location
    Kentucky
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: Formula to replace values if another exists

    I'm referring to the contents of column A. In other words, if Column A contains an "A" keep it as an "A" but if it contains a "B" change all the "A"s to "B"s. The formula I have does this perfectly except I need it to detect multiple values in a cell and change those as well, as in my example from the first post.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Formula to replace values if another exists

    Can you upload a few sample answers please

  8. #8
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Formula to replace values if another exists

    Ok in that case you can modify your formula with below
    =IF(A6="A",IF(ISNUMBER(MATCH("B",$A$1:$A$203,0)),SUBSTITUTE(A6,"A","B"),A6) and add the nested if's with substitute where ever value is true

  9. #9
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Formula to replace values if another exists

    Try this Array Formula in C27. Since this is an array formula so you need to confirm it with Ctrl+Shift+Enter instead of just Enter. (i.e. hold down the Ctrl+Shift and then press Enter)
    Please Login or Register  to view this content.
    and then drag down.

    For detail see the attached sheet.
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to Replace Row if Exists or copy to new row if doesnt exist
    By jgibs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2012, 01:23 PM
  2. 'xxxx already exists in this location, do you wish to replace it' issue
    By lolelner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2012, 01:54 AM
  3. Check if Name exists and replace it with corrected name and ID
    By chris0228 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-05-2012, 07:27 PM
  4. Replace formula values with a blank
    By 4joey1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-12-2010, 11:21 PM
  5. File already exists. Do I want to replace?
    By EMoe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2006, 10:44 PM

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