Easy way to strip text from a number?

I know that I can use: =RIGHT(G1,LEN(G1)-1) to strip the "j" when cell G1 contains "j450" and return a numerical value of 450.


I am just wondering if there is a single Formula to ignore the text part of a cell entry for those inconvenient occasions when cell G1 contains "rj450". In other spreadsheets I have used Formulas such as "texttonum" but cannot seem to locate the equivalent in Numbers. I would have thought that Value(G1) would have worked, but it cannot seem to handle string characters other than currency symbols.


I assume the better method will involve the Value() function, but I am still not sure how to strip out the non-numeric characters. I do know that the alpha characters will all be leading, so LEN can still be part of the formula and I just need to know how to count out the leading alpha characters.

Posted on Feb 17, 2013 7:07 AM

Reply
22 replies

Feb 17, 2013 1:42 PM in response to Martin Gallo

Here is another solution. It takes each character, one at a time, and tries to subtract 0 from it. If it is a number, the subtraction works and we keep the character. If not a number it generates an error and we replace it with "". I only did 7 characters but all it takes to add another character is copy/paste and change one number.


=IFERROR(MID(A1,1,1)-0,"")&IFERROR(MID(A1,2,1)-0,"")&IFERROR(MID(A1,3,1)-0,"")&I FERROR(MID(A1,4,1)-0,"")&IFERROR(MID(A1,5,1)-0,"")&IFERROR(MID(A1,6,1)-0,"")&IFE RROR(MID(A1,7,1)-0,"")

Feb 17, 2013 2:49 PM in response to Martin Gallo

Phew.


The script now detects the selection on any table of any sheet on the front document (in case the original data isn't in table 1 of sheet 1). It creates a new table on the same sheet as the original data, with the stripped values in a single column. All alpha characters are stripped from the original values, as are the character "+" and anything that comes after it.


Again, copy and paste the script into an AppleScript Editor window.


In Numbers, select your data:


User uploaded file


Run the script:


on detect_table()

tell application "Numbers"

tell front document

repeat with x from 1 to count sheets

set this_sheet to sheet x

tell sheet x

repeat with y from 1 to count tables

set this_table to table y

tell table y

try


column of selection range

return {this_table, this_sheet}

end try

end tell

end repeat

end tell

end repeat

end tell

end tell

end detect_table


tell application "Numbers"

try

set {this_table, this_sheet} to my detect_table()

on error number errnum

if errnum = -2763 then

display dialog "Select some data and try again"

end if

return

end try

set the_digits to "1234567890"


set the_cells to cells of selection range of this_table

set cell_count to countthe_cells

tell this_sheet to set nu_table to (make new table at end with properties {row count: (cell_count + 1), column count:1})

repeat with z from 1 to cell_count

set each_cell to itemz of the_cells

try

set the_content to ((value of each_cell) as integer) as text

on error

set the_content to (value of each_cell) as text

end try

set nu_content to ""

set char_count to (countcharacters in the_content)

repeat with x from 1 to char_count

set next_char to characterx of the_content

if next_char is "+" then exit repeat

if next_char is in the_digits then set nu_content to nu_content & next_char

end repeat

set target_cell to cell (z + 1) of column 2 of nu_table

set value of target_cell to nu_content

end repeat

end tell


When I run the script, I get this:


User uploaded file


I would strongly suggest that you try it on a copy of your original spreadsheet.


Hope it helps.


Feb 18, 2013 4:49 PM in response to Martin Gallo

Martin,


It's good that you have sent your feedback to Apple. I'm sure that they keep records on such requests and consider the popularity of such suggestions.


The iWork set of productivity apps seem to concentrate on the basics - the features that almost all users are likely to need. I must say that this request of yours hasn't been seen often here, so you may have a bit of a wait before this feature makes it into the app.


Jerry

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Easy way to strip text from a number?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.