I have an excel sheet with 2 columns: absolute path and relative path.
Now say the data is in below format:
absolute path relative path
 
/a/b/c/d/abc.dat
/x/y/z/def.dat
/p/q/r/s/t/test.dat
/a/b/c/d/abc.dat
/x/y/z/def.dat
The output should be
absolute path relative path
 
/a/b/c/d/abc.dat ABCD_PATH
/x/y/z/def.dat XYZ_PATH
/p/q/r/s/t/test.dat PQRST_PATH
/a/b/c/d/abc.dat ABCD_PATH
/x/y/z/def.dat XYZ_PATH

If the 1st column contains
/a/b/c/d
, then in the 2nd column it should place some unique string which I give here asABCD_PATH
. 
If the 1st column contains
/x/y/z/
, then in the 2nd column it should place some unique string which I give here asXYZ_PATH
. 
If the 1st column contains
/p/q/r/s/t/
, then in the 2nd column it should place some unique string which I give here asPQRST_PATH
.

Create a mapping table in a sheet in your excel file (sheet2 for example):
______________________________________   A  B ____________________________________  1  Absolute  ReplaceBy    2 /a/b/c/d/  ABCD_PATH  3 /x/y/z/  XYZ_PATH  4 /p/q/r/s/t/  PQRST_PATH  _________ ___________________ \ sheet1 /\ sheet2 /\ sheet3 / \______/ \______/ \______/

Back to sheet1:
___________________________________________________   A  B _________________________________________________  1  absolute path  relative path    2 /a/b/c/d/abc.dat  =VLOOKUP(LEFT(A2... (hit)> Ctrl+Shift+Enter  3 /x/y/z/def.dat    4 /p/q/r/s/t/test.dat  V (copy cell)   __________________________________________ \ sheet1 /\ sheet2 /\ sheet3 / \______/ \______/ \______/

Put in
relative path
B2
cell this formula:=VLOOKUP(LEFT(A2, MAX((MID(A2, ROW($1:$90), 1)="/")*ROW($1:$90)) ), Sheet2!$A$2:$B$4, 2, FALSE)

Hit Ctrl+Shift+Enter : it’s an array formula, also known as a CSE formula.

Copy
B2
cell (not the formula) and paste it in the remaining cells in columnB
.
Answer：
How about
=TRIM(SUBSTITUTE(UPPER(LEFT(A1,FIND("~",SUBSTITUTE(A1,"/","~",LEN(A1)LEN(SUBSTITUTE(A1,"/","")))))),"/",""))&"_PATH"
for the path
and =RIGHT(A1,LEN(A1)FIND("~",SUBSTITUTE(A1,"/","~",LEN(A1)LEN(SUBSTITUTE(A1,"/","")))))
for the file and extension
Tags: excelexcel, replace, string