Formula problem when trying to do a nested FIND within LEFT function

colgor

New Member
Joined
Sep 16, 2015
Messages
41
Hi, I am new on this forum, my first post, and hope you can help? I've just started learning about LEFT, RIGHT FIND, MID and LEN. I am practising nesting FIND within the LEFT function. I have pulled some data from an airline website at random, then tried to use FIND to look for a "space" in order to break up the string into two different columns of information. I find that where the information differs, or is not there after the comma in column C, that the result will not return just the first part of the string (which is what I am trying to to). I hope for some tips and that the following will help you understand my issue? Many thanks for any assistance!

Mineta San Jose International Airport | 1701 Airport Blvd. | San Jose, CA 95110 | 408.392.3600
I used formula =LEFT(C9, FIND(" ",C9)-2) in cell D9 then pasted down.
Hit problems when the format after the comma differs, either words
cut off or returns a #value. Can anyone give me a steer on how best
to amend the formula?
UPDATED: Tue Sep-15-15 10:25:05 AM
AirlineFlightFrom (cell C8)City (cell D8)State/Country (cell E8)Sch TimeGateStatus
Southwest805Albuquerque, NMAlbuquerque12:40 PM23On Time
Southwest3109Austin, TXAustin8:50 AM21Arrived 08:45 AM
Alaska2403Boise, IdahoBoise10:00 AM28Arrived 09:53 AM
Southwest2812Burbank, CABurbank8:20 AM20Arrived 08:15 AM
Southwest729Burbank, CABurbank9:35 AM20Arrived 09:25 AM
Southwest1091Burbank, CABurbank11:30 AM22On Time
Southwest2226Chicago, IL-MidwayChicago12:45 PM22On Time
American2452Chicago, IL-O'HareChicago1:14 PM9Now 12:56 PM
Southwest421Dallas, TX-Love FieldDallas12:20 PM20On Time
American2232Dallas/Fort Worth, TXDallas/For10:51 AM9On Time
American89Dallas/Fort Worth, TXDallas/For12:24 PM10Now 12:34 PM
United5592Denver, CODenver9:37 AM13Arrived 09:39 AM
Southwest3198Denver, CODenver10:15 AM22Arrived 10:05 AM
Southwest1091Denver, CODenver11:30 AM22On Time
Southwest2875Denver, CODenver12:45 PM21On Time
United831Denver, CODenver1:10 PM12On Time
Southwest1677Greenville, SCGreenville11:50 AM24On Time
Volaris930Guadalajara#VALUE!12:05 PM16On Time
Southwest508Kansas City, MOKansa11:10 AM20On Time
Southwest2918Las Vegas, NVLa7:35 AM24Arrived 07:25 AM
Southwest1905Las Vegas, NVLa9:05 AM24Arrived 08:55 AM

<tbody>
</tbody>
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
try these for your city and state.

***note change cell references to match your data

city column
Code:
=IF(ISERROR(LEFT(C2,FIND(",",C2)-1)),C2,LEFT(C2,FIND(",",C2)-1))

state column
Code:
=IF(ISERROR(MID(C2,FIND(",",C2)+2,2)),C2,MID(C2,FIND(",",C2)+2,2))

rich
 
Upvote 0
Hi

Welcome to the MrExcel Forum

Try in D9 for the left part (City) :-
Code:
=IFERROR(LEFT(C9,FIND(",",C9)-1),C9)

and in E9 for the right part (State) :-
Code:
=IFERROR(RIGHT(C9,LEN(C9)-(FIND(", ",C9)+2)),"")

hth
 
Last edited:
Upvote 0
Thanks Rich, that worked a treat in terms of a solution, you're a star! There were a couple of records, below, where the format was not the same so did not work but that does not matter for my purposes whilst I am learning. The formula is a little advanced for me at this stage, for we are asked to go look for data and analyse if for an assignment, so can't use it unless I understand how and why I did it? I'll need to go googling or youtubing the ISERROR command so I can justify its inclusion. Thanks again!

AirlineFlightFromCity (cell D8)State/Country (cell E8)Sch TimeGateStatus
Southwest2875Denver, CODenverCO12:45 PM21On Time
United831Denver, CODenverCO1:10 PM12On Time
Southwest1677Greenville, SCGreenvilleSC11:50 AM24On Time
Volaris930GuadalajaraGuadalajaraGuadalajara12:05 PM16On Time
All Nippon172Tokyo-NaritaTokyo-NaritaTokyo-Narita11:00 AM15On Time
Southwest2834Tucson, AZTucsonAZ9:10 AM19Arrived 09:07 AM

<tbody>
</tbody>
 
Upvote 0
Another star, thank you Mike, I'm going to like this website and the helpful folk I find here!
Your solution did not quite work out for the state/E9, see below:

Airline
Flight
From
City (cell D8)
State/Country (cell E8)
Sch Time
Gate
Status
Southwest
805
Albuquerque, NM
Albuquerque
M
12:40 PM
23
On Time
Southwest
3109
Austin, TX
Austin
X
8:50 AM
21
Arrived 08:45 AM
Alaska
2403
Boise, Idaho
Boise
daho
10:00 AM
28
Arrived 09:53 AM
Southwest
2812
Burbank, CA
Burbank
A
8:20 AM
20
Arrived 08:15 AM
Southwest
729
Burbank, CA
Burbank
A
9:35 AM
20
Arrived 09:25 AM
Southwest
1091
Burbank, CA
Burbank
A
11:30 AM
22
On Time
Southwest
2226
Chicago, IL-Midway
Chicago
L-Midway
12:45 PM
22
On Time
American
2452
Chicago, IL-O'Hare
Chicago
L-O'Hare
1:14 PM
9
Now 12:56 PM
Southwest
421
Dallas, TX-Love Field
Dallas
X-Love Field
12:20 PM
20
On Time

<tbody>
</tbody>
 
Upvote 0
Hi

Sorry about the error, here is the correction :-
Code:
=IFERROR(RIGHT(C9,LEN(C9)-(FIND(", ",C9)+2)+1),"")

Thanks for the feedback.

Good luck with your project.
 
Upvote 0
Please don't apologise Mike! Feels a bit like a Spaniard apologising to me on holiday for his poor English, when I as the lazy brit cannot speak a word of Spanish! :) Your new code worked a treat and left spaces where appropriate, for example in the State with Guadalajara and Tokyo. Now I must get googling IFERROR to deconstruct your formulas to properly understand. What I have found is that for a quick solution to a problem at work this site is fantastic, you are too helpful to me whilst I am learning ... aka me cheating! :)
 
Upvote 0
colgor,

I know that you have a solution from Mike but for educational purposes here is another way that you could do it....

Excel 2007
ABCDE
8AirlineFlightFromCity (cell D8)State/Country (cell E8)
9Southwest805Albuquerque, NMAlbuquerqueNM
10Southwest3109Austin, TXAustinTX
11Alaska2403Boise, IdahoBoiseIdaho
Sheet1
Cell Formulas
RangeFormula
D9=TRIM((LEFT(SUBSTITUTE(C9,",",REPT(" ",99)),99)))
E9=TRIM(SUBSTITUTE(SUBSTITUTE(C9,D9,""),",",""))
 
Upvote 0
Thanks Rich, that worked a treat in terms of a solution, you're a star! There were a couple of records, below, where the format was not the same so did not work but that does not matter for my purposes whilst I am learning. The formula is a little advanced for me at this stage, for we are asked to go look for data and analyse if for an assignment, so can't use it unless I understand how and why I did it? I'll need to go googling or youtubing the ISERROR command so I can justify its inclusion. Thanks again!

AirlineFlightFromCity (cell D8)State/Country (cell E8)Sch TimeGateStatus
Southwest2875Denver, CODenverCO12:45 PM21On Time
United831Denver, CODenverCO1:10 PM12On Time
Southwest1677Greenville, SCGreenvilleSC11:50 AM24On Time
Volaris930GuadalajaraGuadalajaraGuadalajara12:05 PM16On Time
All Nippon172Tokyo-NaritaTokyo-NaritaTokyo-Narita11:00 AM15On Time
Southwest2834Tucson, AZTucsonAZ9:10 AM19Arrived 09:07 AM

<tbody>
</tbody>

The iserror is a simple command that looks at a formula to determine if it returns an error. If so it gives the option of what to return rather than the error itself. For example instead of a #value error you could have it return a zero (0). Placing the iserror in an IF statement simply always you to manage errors if they occur. So in this case if the formula returns an error I had it return the cell in column C. otherwise just run the formula itself since it will not return an error.

HTH

Rich
 
Upvote 0
1] City, D9 :

=LEFT(C9,FIND(",",C9&",")-1)

2] State, E9 :

=MID(C9,FIND(",",C9&",")+2,250)
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,783
Members
449,188
Latest member
Hoffk036

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