C# .NET - excel formula or excel VBA code to Retrieve number from a text mixed with number

Asked By Cherifa Hima on 21-Jan-10 04:08 PM

Hi,

Is there an excel formula or excel VBA code to retrieve numbers from a text mixed with numbers knowing that the position of the numbers can change from one word to another, for example :

Sp WSW  (58.3) m/s

 Sp NE  (48) m/s

 Sp E  (60) m/s

 Thanks.

excel formula or excel VBA code to Retrieve number from a text mixed with number

Matthew Johnson replied to Cherifa Hima on 21-Jan-10 04:42 PM

=REPLACE(LEFT(A8,LOOKUP(10,MID(A8,ROW(INDIRECT("1:30")),1)+0,ROW(INDIRECT("1:30")))),1,MIN(FIND(0,SUBSTITUTE(A8&0,{1,2,3,4,5,6,7,8,9},0)))-1,"")+0

Paste that in the formula bar to accept. Then hit CTRL+SHIFT+ENTER to make it as an array.

Had to do a little research, so the exact formula is from:
http://www.excelforum.com/excel-worksheet-functions/630231-extract-number-from-alphanumeric-string.html

The CTRL+SHIFT+ENTER tip came from:
http://office.microsoft.com/en-us/excel/HA011549011033.aspx

The cell number that I am pointing to is A8...

Would like to take credit, but this is more about helping others getting their questions answered...

Jonathan VH replied to Cherifa Hima on 21-Jan-10 05:17 PM

If the numbers will always be within parentheses, as in your examples:

=VALUE(MID(LEFT(A1,FIND(")",A1)-1),FIND("(",A1)+1,99))

excel formula or excel VBA code to Retrieve number from a text mixed with number

Cherifa Hima replied to Jonathan VH on 22-Jan-10 10:09 AM
Thanks to both of you. Your formulas work nice. God Bless.