Left 12 or left 11?

Rocket28

Board Regular
Joined
Jan 23, 2009
Messages
60
Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Is there a way I can write a formula to give me the data 12 from the left or 11 from the left?<o:p></o:p>
<o:p></o:p>
I currently download streams of data that have numerous digits, but it is only the first 11 or 12 that I am interested in for coding. <o:p></o:p>
<o:p></o:p>
The data is separated by an hyphen, and I currently have to use the formula =LEFT(T4,12) for 12 digit numbers which then have a hyphen after it, and then find the items that have 11 digits and then a hyphen, and I use =LEFT(T5,11).<o:p></o:p>
<o:p> </o:p>
I.e. 0100-0001DCA-PL1091 and 3605-0001WC-2<o:p></o:p>
<o:p> </o:p>
This, however, takes a very long time, as there are thousands of lines, and they are all mixed in to one another.<o:p></o:p>
<o:p> </o:p>
Is there a formula I can write so it can give me 11 or 12 digits depending on where the hyphen appears<o:p></o:p>
<o:p> </o:p>
Thanks.<o:p></o:p>
<o:p></o:p>
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try

=LEFT(A1,IF(MID(A1,12,1)="-",11,12))

or

=LEFT(A1,11+(MID(A1,13,1)="-"))
 
Last edited:
Upvote 0
You can almost certainly do this.
Is it ALWAYS the second hyphen ?
If yes, try this
Code:
=LEFT(T5,FIND("-",T5,FIND("-",T5,1)+1)-1)
 
Upvote 0
I am assuming you need the data that is just to the left of the second hypen?

Try:

<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style=";">0100-0001DCA-PL1091</td><td style=";">0100-0001DCA</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style=";">3605-001WC-2</td><td style=";">3605-001WC</td></tr></tbody></table><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style="background-color: #E0E0F0;text-align: center;color: #161120"><th><b>Sheet1</b></th></tr></td></thead></table><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style=" background-color: #E0E0F0;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">B1</th><td style="text-align:left">=LEFT(<font color="Blue">A1,FIND(<font color="Red">"$$",SUBSTITUTE(<font color="Green">A1,"-","$$",2</font>)</font>)-1</font>)</td></tr></tbody></table></td></tr></table><br />
 
Upvote 0
Jon,

Thasnk, but unfortunalty yours doesnt works.

Gerald,

Thanks heaps, works a treat!

Cheers.

In what way does my suggestion not work?
Which one did you try?

The only difference is that I used A1 as the cell containing your string, instead of T4 or T5....Sorry.


Works for me

Excel Workbook
TUV
4Your DataMy 1st formulaMy 2nd formula
50100-0001DCA-PL10910100-0001DCA0100-0001DCA
63605-0001WC-23605-0001WC3605-0001WC
Sheet1
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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