Formula that will extract the first 4 or 5 digits from a cell.

canadian86

Board Regular
Joined
Feb 6, 2011
Messages
53
I need a formula that will extract the first 4 or 5 digits from a cell.

For example:

Store 2321 - Toronto 12-20-2010
Store # 72833- Calgary 12-20-2011
Store 02931 8A - Oakville 04-20-2011

The formula would return:

2321
72833
02931

That would help me a lot.

Thanks.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
With sample text in cell A1

Try this...
Code:
=LOOKUP(99^99,--("0"&MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),
ROW($1:$40))),MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),
ROW($1:$40)))

Example
with A1: Store 02931 8A - Oakville 04-20-2011
the formula returns: 02931


Is that something you can work with?
 
Upvote 0
That seems to be working.. but instead of giving me:

"02931"

it's giving me

"02931 "

Is there a way to remove the extra space at the end?

Thanks a lot!!
 
Upvote 0
Perhaps:

=TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(MID(A1,6,LEN(A1)),"#","")),"-"," ")," ",REPT(" ",254)),255))

Excel Workbook
AB
1Store 2321 - Toronto 12-20-20102321
2Store # 72833- Calgary 12-20-201172833
3Store 02931 8A - Oakville 04-20-201102931
Sheet1
 
Upvote 0
I need a formula that will extract the first 4 or 5 digits from a cell.

For example:

Store 2321 - Toronto 12-20-2010
Store # 72833- Calgary 12-20-2011
Store 02931 8A - Oakville 04-20-2011

The formula would return:

2321
72833
02931

That would help me a lot.

Thanks.
This works on your posted sample data.

=TRIM(MID(A2,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789")),5))
 
Upvote 0
With sample text in cell A1

Try this...
Code:
=LOOKUP(99^99,--("0"&MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),
ROW($1:$40))),MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),
ROW($1:$40)))
Example
with A1: Store 02931 8A - Oakville 04-20-2011
the formula returns: 02931


Is that something you can work with?

I saw a formula like this two time but I'm not understand how does it work. Could anybody show me what behind the curtain, please?
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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