convert text format to number

mwb

Board Regular
Joined
Sep 3, 2004
Messages
88
I am trying to convert existing data from text to number format. the cells contain numbers and text ((123.100grams). The text is always different as is the number of decimal places that need to be retained. Is there a way to pull the number of entered decimal places (i.e. 123.100 = 3) from this string? the Val function will return 123.1 but I loose the displayed decimals if I rewrite the cell Val after changing the format to number. I think I can calculate it by finding the position of the decimal, then finding the position of the last number... not sure how to find the last number though.

Cheers!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
If 123.100grams is in A1,

Try:

B1 =LEFT(A1,MIN(IF(ISNUMBER(SEARCH({"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"},A1)),SEARCH({"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"},A1)))-1)

B1 should return 123.100

C1 =LEN(B1)-FIND(".",B1)

C1 should return 3, for 3 decimal places.
 
Upvote 0
{=LEFT(A1,LEN(A1)-MATCH(TRUE,ISNUMBER(MID(A1,LEN(A1)+1-ROW(INDIRECT("1:"&LEN(A1))),1)+0),0)+1)}

Note: This is an array formula which must be entered using the Control+Shift+Enter key combination. The outermost braces, {}, are not entered by you -- they're supplied by Excel in recognition of a properly entered array formula. For more on this topic see the Excel help topic for "Create an array formula".

EDIT: changed cell reference to A1
 
Upvote 0
Here's 2 cent's worth:

LEFT(A1,MATCH(0,--ISNUMBER(FIND(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),".0123456789")),0)-1)
array entered with control + shift + enter

[edit]
Another variation of my first approach
=LEFT(A1,MATCH(0,--ISNUMBER(--(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)&0)),0)-1)

My First approach did not work for negative numbers, though my second does. (Mark and Barry's also seem to work for negative numbers)
 
Upvote 0
Thank you all!
I have both Barry's and Mark's formulas working and with Oaktree's len formula i have the result that I need.

Question though; I would like to understand the difference between the following:

"...match("a",MID(..." vs "...match(10,--MID(..." I assume the latter is looking for a number not a character, but what does the "--" do? What does the 10 represent?

Thanks again,
Mike
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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