Extract numerics from a cell ?

theta

Well-known Member
Joined
Jun 9, 2009
Messages
960
Hi
Would like an array formula to strip numbers out of a string. I have seen one version using, help appreciated. I think there are some variations of =MID() where the contents of a cell are split into an array (1 character each) then analysed for digits.

ABC01234567/01

I would ideally like 2 formulas :

1. Split all numbers = 0123456701
2. Split before a given character = before *-/ = 01234567
3. Split before a pattern = before 7/ = 0123456

Any thoughts. Array with MID sounds like a good option?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How about
Excel Workbook
ABCD
1ABC01234567/0112345671234561234567010
Sheet1
Excel 2003
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
 
Last edited:
Upvote 0
If 7 and / always occur next to each other then for the 2nd formula

Excel Workbook
ABCD
1ABC01234567/0112345671234561234567010
Sheet1
Excel 2003
Cell Formulas
RangeFormula
C1=LEFT(B1,LEN(B1)-1)+0
 
Upvote 0
1st formula courtesy of Ron Coderre:

Excel Workbook
ABCD
1ABC01234567/01123456701< All Nums
21234567< before /
3123456< before 7/
Sheet1
Excel 2007
Cell Formulas
RangeFormula
C1=SUMPRODUCT(MID(0&A1,LARGE(INDEX(ISNUMBER(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))*ROW(INDIRECT("1:" & LEN(A1))),0),ROW(INDIRECT("1:" & LEN(A1))))+1,1)*10^ROW(INDIRECT("1:" & LEN(A1)))/10)
C2=-LEFT(-C1,LEN(C1)-(LEN(A1)-FIND("/",A1)-1))
C3=-LEFT(-C1,LEN(C1)-(LEN(A1)-FIND("7/",A1)-1))
 
Upvote 0
Hmmm....for the pattern match (7/) thought maybe could use COUNTIF array so that I may enter multiple patterns "on" "out" "7/" "hi"

Seen some usage like :

SUM(COUNTIF($B6:$AP6,{"x","d","m","e"})

http://office.microsoft.com/en-us/e...rs-from-alphanumeric-strings-HA001154901.aspx


Very elegant solutins, but not exactly what I need, yours look closer but want to use simple arrays rather than being too prescriptive ?
 
Upvote 0
Another alternative which is not array posted by Bosco

FOR ALL NOS.

=-LOOKUP(2,-RIGHT(SUBSTITUTE(A1,"/",""),ROW($1:$99)))

and for remaining two requirement, you could use Jons formula for non array or Sandeep's formula for array.

regards,

Vinod
 
Upvote 0
I've tried some User-Defined Functions. Code pasted into a standard module and then formulas used in the sheet as shown and copied down.

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> RX <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CreateRX()<br><SPAN style="color:#00007F">Set</SPAN> RX = CreateObject("VBScript.RegExp")<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Function</SPAN> AllNumbers(<SPAN style="color:#00007F">ByVal</SPAN> s <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>)<br>    <SPAN style="color:#00007F">If</SPAN> RX <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> CreateRX<br>    <SPAN style="color:#00007F">With</SPAN> RX<br>        .Pattern = "[^0-9]"<br>        .Global = <SPAN style="color:#00007F">True</SPAN><br>        <SPAN style="color:#00007F">If</SPAN> Len(.Test(s)) <= Len(s) <SPAN style="color:#00007F">Then</SPAN><br>            AllNumbers = .Replace(s, "") + 0<br>        <SPAN style="color:#00007F">Else</SPAN><br>            AllNumbers = ""<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN><br><br><SPAN style="color:#00007F">Function</SPAN> BeforeStr(<SPAN style="color:#00007F">ByVal</SPAN> s <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, sStr <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>)<br>    <SPAN style="color:#00007F">If</SPAN> RX <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> CreateRX<br>    <SPAN style="color:#00007F">With</SPAN> RX<br>        .Pattern = sStr & ".*"<br>        .Global = <SPAN style="color:#00007F">True</SPAN><br>        <SPAN style="color:#00007F">If</SPAN> .Test(s) <SPAN style="color:#00007F">Then</SPAN><br>            BeforeStr = AllNumbers(.Replace(s, "")) + 0<br>        <SPAN style="color:#00007F">Else</SPAN><br>            BeforeStr = ""<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN></FONT>


Excel Workbook
ABCD
1All_NumbersBefore *-/Before 7/
2ABC01234567/011234567011234567123456
3fsd
45463454634
5XYZ89766/99897669989766
6CBGH1235KJ7/124MM12357124123571235
Extract cell characters
 
Upvote 0
Hi Jon....can you please breakdown your C1 formula for a full analysis so that I can develop it going forward. Looks like a more dynamic version of the array types i mentioend previously

Thanks

Luke
 
Upvote 0

Forum statistics

Threads
1,214,399
Messages
6,119,279
Members
448,884
Latest member
chuffman431a

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