How can I combine multiple nested Substitute functions in Excel?

后端 未结 5 1815
Happy的楠姐
Happy的楠姐 2021-01-17 08:35

I am trying to set up a function to reformat a string that will later be concatenated. An example string would look like this:

Standard_H2_W1_Launch_123x456_         


        
5条回答
  •  别那么骄傲
    2021-01-17 09:27

    To simply combine them you can place them all together like this:

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"_AB","_"),"_CD","_"),"_EF","_"),"_40K",""),"_60K",""),"_S_","_"),"_","-")
    

    (note that this may pass the older Excel limit of 7 nested statements. I'm testing in Excel 2010


    Another way to do it is by utilizing Left and Right functions.

    This assumes that the changing data on the end is always present and is 8 characters long

    =SUBSTITUTE(LEFT(A2,LEN(A2)-8),"_","-")
    

    This will achieve the same resulting string


    If the string doesn't always end with 8 characters that you want to strip off you can search for the "_S" and get the current location. Try this:

    =SUBSTITUTE(LEFT(A2,FIND("_S",A2,1)),"_","-")
    

提交回复
热议问题