+ Reply to Thread
Results 1 to 13 of 13

Remove certain characters from end of string

  1. #1
    Registered User
    Join Date
    07-10-2019
    Location
    sheffield,england
    MS-Off Ver
    office 2019
    Posts
    18

    Remove certain characters from end of string

    I have a database of design but can have up to 8 different suffixes depending who they are for but basically its the same item

    I need a way of remove certain characters from the end of string as per the supplied sample
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: Remove certain characters from end of string

    In A2-A6, you deleted all alpha chars after the last digit. A7, you deleted only 3 of 5, A8, 2 of 4, so what's the rule? Do you have a list of suffixes?
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    07-10-2019
    Location
    sheffield,england
    MS-Off Ver
    office 2019
    Posts
    18

    Re: Remove certain characters from end of string

    The suffixes are CL ,AS , ZNK , MHT , HMT , TE , LE and possibly more over time

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,998

    Re: Remove certain characters from end of string

    Do you have a list of core codes (without these suffixes)?

    Excel needs something to use to establish a pattern. Your sample dataset has only two patterns, and there is nothing there that can readily be used to tell Excel what to do.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    07-10-2019
    Location
    sheffield,england
    MS-Off Ver
    office 2019
    Posts
    18

    Re: Remove certain characters from end of string

    I have a list of 3500 core codes with more been added weekly
    Basically I need a formula or macro that will look at the code and if it ends with one of the suffixes remove the suffix
    If the suffixes were the same length I have a working formula because they are 2 or 3 characters in length this doesn’t work

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,998

    Re: Remove certain characters from end of string

    OK - so the only way you will be able to achieve this is to have a dynamic list of suffixes that can be added to. You cannot do it without a reference array. Do you understand this?

    This means that you will need to work with a table containing the suffixes that can be referenced.

  7. #7
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 365
    Posts
    2,406

    Re: Remove certain characters from end of string

    Just for your example, put this on B2 and copied down and Im using helper table:

    =IFERROR(SUBSTITUTE(A2,MID(A2,IFERROR(LOOKUP(2*15,SEARCH($F$2:$F$8,SUBSTITUTE(SUBSTITUTE(A2,",","")," ",""))),""),100),""),A2)
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    07-10-2019
    Location
    sheffield,england
    MS-Off Ver
    office 2019
    Posts
    18

    Re: Remove certain characters from end of string

    Many thanks works perfectly ,just what I needed

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,998

    Re: Remove certain characters from end of string

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  10. #10
    Registered User
    Join Date
    07-10-2019
    Location
    sheffield,england
    MS-Off Ver
    office 2019
    Posts
    18

    Re: Remove certain characters from end of string

    Many thanks when I try to expand the table of suffixes to include to cell f10 it doesn't work

    I was hoping to just change $F$2:$F$8 to $F$2:$F$10

    Can you let me know where I am going wrong

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,998

    Re: Remove certain characters from end of string

    Should work as long as those cells in row 9 and 10 are not blank.

    This is why I suggested that you need something that will adjust dynamically like a table.

    In the attached you will find that I've converted your lookup list to a table - this will now adjust when you add new codes to it, and the formula will adapt automatically, too.
    Attached Files Attached Files
    Last edited by AliGW; 07-11-2019 at 05:40 AM.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,998

    Re: Remove certain characters from end of string

    Just posting again in case you missed the attachment I added to my last post.

  13. #13
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Remove certain characters from end of string

    I have also spent some time with your duplicate thread, so just posting my solution in this thread.

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    Please Login or Register  to view this content.
    In B2 Cell

    =RemoveSuffix(A2,Table1[Suffixes])

    Drag the B2 cell formula down.
    Attached Files Attached Files


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

+ 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] Remove characters from string from the right after 4 characters
    By dlemley in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-10-2017, 08:47 AM
  2. VBA to remove characters from a string
    By ed67 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-06-2015, 12:46 PM
  3. [SOLVED] VBA, remove all characters within a string, except numerical characters and full stops
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-25-2015, 09:24 PM
  4. [SOLVED] VBA Remove First 10 Characters From string
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-16-2013, 08:22 AM
  5. [SOLVED] Remove certain characters from the end of a string only
    By mini_dutch28 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 12-20-2012, 01:04 PM
  6. Remove characters in a string.
    By jncswe in forum Excel General
    Replies: 2
    Last Post: 09-10-2010, 07:26 AM
  7. Remove Characters From Right of String
    By milagros in forum Excel General
    Replies: 11
    Last Post: 12-26-2009, 12:01 PM

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