Using len and left functions together

CRISTINA1128

New Member
Joined
Jun 21, 2016
Messages
9
I have the following data:
15ab
12cc
6ll
9bc

and i need to extract the number portion of the string. My text string will be either 3 or 4 characters long.
If len=4, then left,2. If len=3, then left,1.

I can't make the formula work in excel. Can someone please help?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hrm, perhaps this:

=IF(LEN(A2)=4,LEFT(A2,2),LEFT(A2,1))

This is assuming that your len is ONLY 3 or 4 as you stated. If it is more or less, then the formula will need adjustment.
 
Upvote 0
To do what you want you can try this, and I'm sure there are other ways to do this as well.

Code:
=IF(LEN(A1)=4,LEFT(A1,2),LEFT(A1,1))
 
Upvote 0
Last question - this text string is in a pivot table and i was trying to insert a calculated field. I was replacing "a1" with the column header, which in this case is "casepack/eaches size". However, the result i'm getting is "# of packs" on 1 line and "sum of casepack" on the line below it....
Any advise?
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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