Convert Text String To Numbers

paulkc

Board Regular
Joined
May 18, 2007
Messages
220
Office Version
  1. 365
I have a spreadsheet containing several thousand records. I am trying to extract certain parts of a certain field. This field contains a text string that might be something like "001-018" or "003". I want to extract into 2 different columns the first number and the last number (if there is one). If column A contains the "001-018" then I want column B to have "1" and column C to have "18". If column A contains "003" then column B would have "3" and column C would be left blank. I can't figure out the correct formulas to do this. Thanks for the help.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
paulkc,

We need to see more examples of the data in column A, and the manual results in columns B and C.

What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:

If you are not able to give us screenshots, see below in my Signature block: You can upload your workbook to Box Net
 
Upvote 0
Try...

B2:

=LEFT(A2,FIND("-",A2&"-")-1)+0

C2:

=IF(ISNUMBER(FIND("-",A2)),REPLACE(A2,1,FIND("-",A2),"")+0,"")
 
Upvote 0
Aladin, that worked great except for one thing. I noticed that some of the data in column contains some strange exceptions to my previous rule. I noticed one of the cells contains something like "001--003" (notice the extra dash). Another had "001-'003". The formula in column C returns "-3" for the first instance but an error for the second instance. Would it be possible to modify the formula to account for these types of inconsistencies or would I just need to rectify these manually?
 
Upvote 0
Aladin, that worked great except for one thing. I noticed that some of the data in column contains some strange exceptions to my previous rule. I noticed one of the cells contains something like "001--003" (notice the extra dash). Another had "001-'003". The formula in column C returns "-3" for the first instance but an error for the second instance. Would it be possible to modify the formula to account for these types of inconsistencies or would I just need to rectify these manually?

B2:

=LEFT(A2,FIND("-",A2&"-")-1)+0

C2:

=IF(ISNUMBER(FIND("-",A2)),ABS(SUBSTITUTE(REPLACE(A2,1,FIND("-",A2),""),CHAR(39),"")+0),"")

If you have more exceptions, a routine in VBA would be more appropriate to sollicite for.
 
Upvote 0
Also try,

B2;

=LEFT(SUBSTITUTE(A2&"-","-",REPT(" ",50)),50)+0

C2;

=IF(ISNUMBER(FIND("-",A2)),SUBSTITUTE(RIGHT(SUBSTITUTE(A2,"-",REPT(" ",50)),50),CHAR(39),"")+0,"")
 
Upvote 0
Is there some way to do this so that is separates the numbers regardless of what is in between? I have run into a lot of inconsistencies in these numbers. Everything from the original 001-003 to 1~3 or 1/.3, etc. Any suggestions?
 
Upvote 0
paulkc,

To solve your request correctly, we need to see your raw data, and we need to see the results manually entered by you in columns B and C.

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:

If you are not able to give us screenshots, see below in my Signature block: You can upload your workbook to Box Net
 
Upvote 0
Ok, here is a sample of the data. I cannot guarantee that this is all the possible characters because as you can see there is no rhyme or reason to the way the range was indicated. I am cleaning up quite a few of these and then importing them into an Access Database.
Excel Workbook
CDE
110~10
212~12
317~271727
431/`343134
51_515
61212
7001-00313
8003-012312
Sheet1
Excel 2010
 
Upvote 0
This is not an ideal solution, it is slow to calculate, and volatile, but it would give you a "standard" format that you could maybe copy / pastespecial, then delimit with text to columns using "space" as delimiter.

Note that MCONCAT requires the MOREFUNC add-in.
Excel Workbook
AB
410~10
512~12
617~2717 27
731/`3431 34
81_51 5
91212
10001-003001 003
11003-012003 012
Sheet
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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