+ Reply to Thread
Results 1 to 2 of 2

Clearer way to do Mutli-replace?

Hybrid View

  1. #1
    Registered User
    Join Date
    01-27-2006
    Posts
    4

    Clearer way to do Mutli-replace?

    I have a column in Excel that needs to clean up the string before some of the items have URL-Safe encoding in it and then grab the actual Receipt number.


    This list....
    Receipt 20Number 202017310 2E001 20refund
    Receipt 20Number 201102323 2E001 20charge
    Receipt 20Number 202017314 2E001 20refund
    Receipt Number 1074202.005
    Receipt Number 1074204.005
    Receipt 20Number 201102332 2E001 20charge

    Would then turn into....
    2017310.001
    1102323.001
    2017314.001
    1074202.005
    1074204.005
    1102332.001

    So i have managed to do it, but i'm wondering if there is a cleaner way of doing this without having to resort to a Macro? I have 3 instances of the cell i'm using (in this case I1487). I figure out if its the kind of string where i need to replace the extra characters then remove the characters are pre-defined points.

    Its more or less doing this:
    Does string contain 'Receipt 20Number'
    1. Remove End characters ( IE: '20refund')
    2. Change ' 2E00' to '.00'
    3. Change ' 20' to ' ' (AfterNumber)
    4. Change ' 20' to ' ' (Before Number)

    =MID(IF(ISERROR(FIND("Receipt 20Number 20",I1487,1)),I1487,REPLACE(REPLACE(REPLACE(REPLACE(I1487,33,9,""),27,3,"."),17,3," "),8,3," ")),16,11)

    Not a big problem since i have it working but i'm worried about someone in the future looking at the excel sheet and going 'what the heck is this doing'

    Thanks for your help.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Clearer way to do Mutli-replace?

    Here is another formula that should do the same thing:

    =TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(I1487,"20refund",""),"20charge","")," 2E001",".001")," 20"," "),"Receipt Number",""))

    In this case, it is easier to follow what is actually being substituted.... so might be easier to understand.

    The TRIM() will clean any stray spaces...before, after or in between.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

+ 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