Google Search

Custom Search
Showing posts with label RIGHT FUNCTION. Show all posts
Showing posts with label RIGHT FUNCTION. Show all posts

How to find the position of last of the multiple characters in a cell

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

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]  (W
hich 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.


LEN(SUBSTITUTE(A1,"\",""))
21
LEN(A1)
23
LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))
2
SUBSTITUTE(A1,"\","#",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))
drive1\folder1#file1023
FIND("#",SUBSTITUTE(A1,"\","#",LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))))
15
RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/","")))))
file1023



Please let me know if you have any concerns or questions.

How to use DATE, RIGHT and LEFT formulas to create date from unique IDs


Prerequisite 

Know how to use "DATE", "RIGHT" and "LEFT" formulas individually.
Please refer to Microsoft help for Syntax.



Possible Usage


In the earlier post we talked about how to create unique IDs using data code or time stamp. Here we will see how to do the reverse. This kind of situation does arises in Operation or Manufacturing environments.

”how


The steps (How to do)



To create date we need year, month and day.

”how


1. Type =LEFT(F2,4). Drag or copy paste the formula all the way (to cover the all the IDs). This will be the year.

2. Type =RIGHT(LEFT(F2,6),2) Drag or copy paste the formula all the way (to cover the all the IDs). This will be the month.

3. Type =RIGHT(LEFT(F2,8),2) Drag or copy paste the formula all the way (to cover the all the IDs). This will be the day.

4. Type =DATE(E2,D2,C2) Drag or copy paste the formula all the way (to cover the all the IDs). This will be the date.

”how


DONE.

All comments are welcome.

 

blogger templates | Make Money Online

Google Analytics Alternative ExpiresDefault access plus 1 year