+ Reply to Thread
Results 1 to 12 of 12

Change last character(s) in multiple words in a cell

  1. #1
    Registered User
    Join Date
    05-07-2013
    Location
    Celje, Slovenia
    MS-Off Ver
    2016, 365
    Posts
    29

    Change last character(s) in multiple words in a cell

    Hello!

    I'd like to know how to change the last character(s) (or add or delete a character) in each word, when there are 2 or more words in a cell. Of course, this change or replacement should be based on certain rules, such as (I apologize, but I'll have to write all the examples in my language):

    if any words in a cell ends with "ev", it should be changed so that it ends with "evega" (for example natrijev > natrijevega)
    if any words in a cell ends with "id", it should be changed so that it ends with "ida" (for example klorid > klorida)
    if any words in a cell ends with "na", it should be changed so that it ends with "ne" (for example kislina > kisline)
    and so on....
    ...


    So if I have "natrijev klorid" written in a cell it should be changed to "natrijevega klorida" or "acetilsalicilna kislina" should be changed to "acetilsalicilne kisline" or "natrijev metamizolat monohidrat" should be changed to "natrijevega metamizolata monohidrata".

    I think it would be easier using a formula, but I kinda do not know how to start.
    So I would very much appreciate your help.


    Regards

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Change last character(s) in multiple words in a cell

    You can use this method

    Where A1 contains the text to be modified;

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"ev","evega"),"id","ida"),"na","ne")

    Color coded, Blues are with Blues, Reds with Red/Orange, Black with Black. You can continue to add like this if you have more phrases to change, just add another substitute( at the start of the formula, and add ,"ReplaceThis","WithThis") at the end.
    Last edited by Speshul; 07-31-2014 at 02:50 PM.
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  3. #3
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Change last character(s) in multiple words in a cell

    Quote Originally Posted by Speshul View Post

    =substitute(a1,"ev","evega")
    That would change

    "every week has seven days" to "evegaery week has sevegaen days"

    We want specifically only if the word 'Ends' with ev

    Try
    =substitute(a1&" ","ev ","evega ")

  4. #4
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Change last character(s) in multiple words in a cell

    send as sample of the cells in your language

    also include in a separate sheet the rules
    A1 ev B1 evega
    A2 id B2 ida
    A3 na B3 ne...

  5. #5
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Change last character(s) in multiple words in a cell

    "every week has seven days" to "evegaery week has sevegaen days"

    Hahaha, good point!

  6. #6
    Registered User
    Join Date
    05-07-2013
    Location
    Celje, Slovenia
    MS-Off Ver
    2016, 365
    Posts
    29

    Re: Change last character(s) in multiple words in a cell

    Thank you all for the quick response. Since I'm no longer at work and I do not have access to the file, I'm going to finally test the proposed solution tomorrow. But after a quck test I've done I think that Speshul's solution
    Quote Originally Posted by Speshul View Post

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"ev","evega"),"id","ida"),"na","ne")
    with Jonmo1's correction

    Quote Originally Posted by Jonmo1 View Post

    Try
    =substitute(a1&" ","ev ","evega ")
    should work.


    Quote Originally Posted by rcm View Post
    send as sample of the cells in your language

    also include in a separate sheet the rules
    A1 ev B1 evega
    A2 id B2 ida
    A3 na B3 ne...
    rcm thank you for your offer.
    If it turns out that the proposed solution does not work, I will send you the sample and rules.

    Regards

  7. #7
    Registered User
    Join Date
    05-07-2013
    Location
    Celje, Slovenia
    MS-Off Ver
    2016, 365
    Posts
    29

    Re: Change last character(s) in multiple words in a cell

    Today I tested the proposed solution. Unfortunately, I have to say that the proposed solution does not work in all cases. The problem is related to the order of the rules in the formula.

    As you can see on the sheet with examples in the attached file, I get different results when rules were sorted alphabetically by ascending or descending order. Errors are the result of the fact that one rule invalidate the other.

    For Example

    How it's written now How should be what I get using formula1* what I get using formula2**
    etanercept etanercepta etanercepta etanercepte


    *Formula 1: Rules sorted from Z to A
    **Formula 2: Rules sorted from A to Z

    If you look at the rules sheet, you can see that words ending with "ept" should change to end with "epta". The other rule requires that the ending "ta" is changed to "te".
    The order of the rules in the formula is obviously important. When the rule "ept" to "epta" is before the rule "ta" to "te" (as in formula2), then the result is wrong (as in marked in the above table).

    I got the table yesterday and at first glance it seemed to me that I will not need so many rules, so that a simple formula would be quite enough.
    After more detailed checking I realized that I would need at least 60 different rules.
    The table is quite large, almost 20,000 records (and records are still being added). I'm not the administrator of the original table and have no impact on how the data is entered into the the table.

    So any additional suggestion or solution will be appreciated.

    Regards
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    07-22-2014
    Location
    Riyadh
    MS-Off Ver
    2010
    Posts
    88

    Re: Change last character(s) in multiple words in a cell

    hi
    i think the attached sheet wil help you.....
    Attached Files Attached Files

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Change last character(s) in multiple words in a cell

    OK, I have a working VBA code that does all the rules without Re-Doing one that was already done by a previous rule.
    However, I don't understand the reasoning behind the ones you marked to NOT change.

    How can any solution we provide know which ones to NOT apply the changes to?

  10. #10
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Change last character(s) in multiple words in a cell

    Example book

    EFfrankt68.xlsm

  11. #11
    Registered User
    Join Date
    05-07-2013
    Location
    Celje, Slovenia
    MS-Off Ver
    2016, 365
    Posts
    29

    Re: Change last character(s) in multiple words in a cell

    Quote Originally Posted by mohamedJamsheer View Post
    hi
    i think the attached sheet wil help you.....
    Thanks for your help, but unfortunately the results are correct only for cells with only one word in them. For cells with two or more words, only the last word is correctly converted.

  12. #12
    Registered User
    Join Date
    05-07-2013
    Location
    Celje, Slovenia
    MS-Off Ver
    2016, 365
    Posts
    29

    Re: Change last character(s) in multiple words in a cell

    Quote Originally Posted by Jonmo1 View Post
    Example book

    Attachment 336337
    Thank you, iz works!

    Regarding your previous remark

    Quote Originally Posted by Jonmo1 View Post
    OK, I have a working VBA code that does all the rules without Re-Doing one that was already done by a previous rule.
    However, I don't understand the reasoning behind the ones you marked to NOT change.

    How can any solution we provide know which ones to NOT apply the changes to?
    All cells that contain punctuation (eg, comma, full stop, semicolon, dash), square brackets, parentheses and numbers, I need to check manually, because they do not comply with any rule. Fortunately, there are not many of such records, and can be easily filtered out.

    As I said, I'm very pleased with the solution, but I still have one more request. Would you be so kind and explain to me how this function works, so I would also understand it?

    Regards

+ 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. [SOLVED] Break Cell based on character count-w/o splitting words-Help
    By mnfez in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 12-19-2013, 09:05 AM
  2. Search a cell for multiple words and return multiple results in one cell
    By samanthat86 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-23-2013, 12:01 PM
  3. Change Cell Strings in Column to Replace Specifically the Second Character
    By Steve794421 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2013, 09:36 AM
  4. Change color of cell depending on character in string
    By delirium in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2011, 04:47 PM
  5. Change a specific character in a cell
    By blitz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2010, 06:48 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