Let's look at the example here. There are cells that contain something similar to
drive1\folder1\file1023
drive2\folder2\subfolder2\file256
drive10\file34
..
..
..
The text after the last "/" is to be extracted, the result should be,
file1023
file256
file34
..
..
To do that you need position of the last "/". FIND function alone is not use because of two unknowns, one how many "/" s are there and second what is the "start number" to use.
But it is possible using RIGHT, FIND, SUBSTITUTE and LEN.
Let's say drive1\folder1\file1023 is in cell A1.
The formula to get file1023 will be
drive1\folder1\file1023
drive2\folder2\subfolder2\file256
drive10\file34
..
..
..
The text after the last "/" is to be extracted, the result should be,
file1023
file256
file34
..
..
To do that you need position of the last "/". FIND function alone is not use because of two unknowns, one how many "/" s are there and second what is the "start number" to use.
But it is possible using RIGHT, FIND, SUBSTITUTE and LEN.
Let's say drive1\folder1\file1023 is in cell A1.
The formula to get file1023 will be
RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))))) Note '#' can be any character. Let's analyse the formula to see how it works. The formula works using [instance_num] (Which is not available in FIND function) of the SUBSTITUTE function and substituting "\" with "" (or nothing). SUBSTITUTE(text, old_text, new_text, [instance_num])
Lets look at the formula from right to left. LEN(SUBSTITUTE(A1,"\","")) will give number of characters after replacing "\" with "". LEN(A1) will give number of characters before any change. The difference is the number of "\" in the cell, in this example 2. SUBSTITUTE(A1,"\","#",LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))) will replace only the last "\" with "#" using 2 as the [instance_num ]. Now "#" is in the last "\" position. Now using FIND the position of "#" can be found, in this example 15. Using RIGHT formula with identified position of the "#" it is possible to extract file 1023.
Please let me know if you have any concerns or questions. |
Hi, thanks for this excel tutorial. I Am Learning Excel Now, and this material make me understand more
ReplyDelete