Help with formulas: Left Right Mid Substitute etc...

Desu Nota from Columbus

Well-known Member
Joined
Mar 17, 2011
Messages
556
I need to learn and understand how to do the following:

Take something like this: 123/Banana

to: 123 or: Banana


How do you search for a specific character, and then say return all characters to the left or right?

Examples:

1) aaaa-bbbbb-cc-ddddddd ---> aaaabbbbbccdddddd

2) A-1234/REDRUM ----> A1234REDRUM

3) 12/23/2006 - 12:54:33 -----> either 12/23/2006 or 12:54:33


Thanks,

Josh
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
There are several approaches you might use.
Here are some:

With A1: 123/Banana
these formulas return: 123 and Banana
B1: =LEFT(A1,FIND("/",A1)-1)
C1: =SUBSTITUTE(A1,B1&"/","")

With A1: aaaa-bbbbb-cc-ddddddd
this formula returns: aaaabbbbbccddddddd
B1: =SUBSTITUTE(A1,"-","")

With A1: A-1234/REDRUM
this formula returns: A1234REDRUM
B1: =SUBSTITUTE(SUBSTITUTE(A1,"-",""),"/","")

With A1: 12/23/2006 - 12:54:33 PM
these formulas return: 12/23/2006 and 12:54:33 PM
B1: =--TRIM(LEFT(A1,FIND("-",A1)-1))
C1: =TRIM(RIGHT(A1,LEN(A1)-FIND("-",A1)))

Does that help?
 
Upvote 0
Just a few examples of many possibilities, in each case A1 is used as the cell holding the data

1) =substitute(A1,"-","")

2) =substitute(substitute(A1,"-",""),"/","")

3) Has multiple answers depending on the format of the data
For date =int(A1) or =trim(left(A1,find("-",A1)))
For time =mod(A1,1) or = trim(mid(A1,find("-",A1),len(A1))) or =trim(substitute(A1,left(A1,find("-",A1)),""))
 
Upvote 0
Thanks for the responses everyone! I understand what I am seeing, I will definitely do a couple practice runs to cement in my mind.

I have a couple questions to help understand why this works:

LEN(A2)-FIND("/",A2)

Does the Find() function return a position of a character essentially making the this phrase return a number (pertaining to a the amount of characters to return)?


=LEFT(A2,FIND("/",A2)-1)
Assuming the answer (from above) is 'yes the find function returns the position of the character', why do you need -1? And what does the -1 mean?

Could you do something like this? =LEFT(A2, ABS((LEN(A2)-LEN(A2)-FIND("/",A2))+1)
 
Last edited:
Upvote 0
FIND returns the character position reading from left to right. If you want what is to the left of that character you need to subtract 1
 
Upvote 0
Does the Find() function return a position of a character essentially making the this phrase return a number (pertaining to a the amount of characters to return)?

Yes, it does.

=LEFT(A2,FIND("/",A2)-1)
Assuming the answer (from above) is 'yes the find function returns the position of the character', why do you need -1? And what does the -1 mean?

Using the find fuction alone would return the position of "/", so in 123/Banana it would return 4, if you wanted the result to be what is before "/" then that is only 3 characters, or (4) -1

Could you do something like this? =LEFT(A2, ABS((LEN(A2)-LEN(A2)-FIND("/",A2))

You could but it would be pointless, cutting it apart, ABS((LEN(A2)-LEN(A2)-FIND("/",A2) would return exactly the same as FIND("/",A2)

LEN()-LEN() = 0 so all you're doing is ABS(-FIND()) which is the same as FIND()
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,758
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top