Avatar of Euro5
Euro5Flag for United States of America

asked on 

Extract characters from string

I am trying to isolate characters before and after a comma in a cell.
It is not working though, as it is sometimes including the comma as well as other characters.

For instance the following should be JUAN but I am getting , JUAN.

There are other variations.

I need the name before the comma and the name after the comma.

I am using =RIGHT(C4,(FIND(",",C4,1)-1)) and =LEFT(C2,(FIND(",",C2,1)-1))

 The LEFT works well but the RIGHT does not.
Can anyone help please!???


ARRE, JUAN, JUAN


Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Rob Henson
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

is "ARRE, JUAN      , JUAN" the contents of cell C4?
Avatar of byundt
byundt
Flag of United States of America image

Try +1 for the right side. Also, consider using MID.
=MID(C4,FIND(",",C4 & ",")+1,99)

Open in new window

I concatenated a comma to the end of C4 in the FIND to avoid an error if the C4 text doesn't contain a comma.

The 99 is an arbitrary number. It should be larger than the maximum length of the returned value. Some people use LEN(C4) instead, but I try to simplify.
ASKER CERTIFIED SOLUTION
Avatar of byundt
byundt
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of byundt
byundt
Flag of United States of America image

If you don't want to use a formula at all, you might use the Data...Text to Columns ribbon item with a comma as the delimiter. The right portion of the text will have a leading space if the original text included one after the comma.
Avatar of byundt
byundt
Flag of United States of America image

If you want to understand how to use the RIGHT function, consider either of:
=RIGHT(C4,LEN(C4)-FIND(",",C4 & ",")-1)
=TRIM(RIGHT(C4,LEN(C4)-FIND(",",C4 & ",")))

Open in new window

Avatar of Euro5
Euro5
Flag of United States of America image

ASKER

Yes, Martiin.
 is "ARRE, JUAN      , JUAN" the contents of cell C4?
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

When using FIND it starts at the start of the text so combined with the RIGHT function doesn't always work.

With your example
ARRE, JUAN      , JUAN

=RIGHT(C4,(FIND(",",C4,1)-1))

The FIND will be finding the first comma after ARRE, which is the fifth character, then deduct 1. The RIGHT function then takes that figure (4) and takes the four characters from the right hand end of the text. In this instance that works because JUAN is only 4 characters.

With a different example:
BOND, JAMES      , JAMES
Comma is character 5, less 1 gives 4, rightmost 4 characters gives "AMES"

BLOGGS, FRED      ,FRED
Comma is character 7, less 1 gives 6, rightmost 6 characters gives " ,FRED"

Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo