Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default UDF for extracting only numeric values.

Any UDF code to have entries like following:

1234Text
12Text34
Text1234

be converted to:

1234
1234
1234

Thanx in advance!
--
Best Regards,

Faraz
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default UDF for extracting only numeric values.

The function will return 0 if there is no digits in the string. I can modify
this to return a Null string very easily.

Function GetNum(Data As String)
GetNum = ""
For CharPos = 1 To Len(Data)
Char = Mid(Data, CharPos, 1)
If IsNumeric(Char) Then
GetNum = GetNum & Char
End If

Next CharPos
GetNum = Val(GetNum)
End Function

"Faraz A. Qureshi" wrote:

Any UDF code to have entries like following:

1234Text
12Text34
Text1234

be converted to:

1234
1234
1234

Thanx in advance!
--
Best Regards,

Faraz

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default UDF for extracting only numeric values.

Hi,

How about a formula with your string in A1. This is an array formula, see
below. Once array entered then drag down as required.
With respect to
Lars-Ã…ke Aspelin who first posted it.

=MID(SUMPRODUCT(--MID("01"&A1,SMALL((ROW($A$1:$A$300)-1)*ISNUMBER(-MID("01"&A1,ROW($A$1:$A$300),1)),ROW($A$1:$A$300)) +1,1),10^(300-ROW($A$1:$A$300))),2,300)


This is an array formula which must be entered by pressing CTRL+Shift+Enter
'and not just Enter. If you do it correctly then Excel will put curly brackets
'around the formula {}. You can't type these yourself. If you edit the formula
'you must enter it again with CTRL+Shift+Enter.

Mike
"Faraz A. Qureshi" wrote:

Any UDF code to have entries like following:

1234Text
12Text34
Text1234

be converted to:

1234
1234
1234

Thanx in advance!
--
Best Regards,

Faraz

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default UDF for extracting only numeric values.

On Fri, 2 Oct 2009 02:54:01 -0700, Faraz A. Qureshi
wrote:

Any UDF code to have entries like following:

1234Text
12Text34
Text1234

be converted to:

1234
1234
1234

Thanx in advance!


=====================
Function Nums(s As String)as String
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "\D+"
Nums = re.Replace(s, "")
End Function
========================

Note that by returning the result as String, leading zero's can be retained. If
this is not wanted or desireable, then return result as Long or as Double.
--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TO DELETE ONLY NUMERIC VALUES IN A CHARACTER AND NUMERIC CELL IN ramesh k. goyal - abohar[_2_] Excel Discussion (Misc queries) 1 October 28th 09 06:50 AM
Return Numeric Labels that have different Numeric Values Sam via OfficeKB.com Excel Worksheet Functions 8 December 3rd 06 02:06 AM
extracting just numeric value out from alphaneumeric cell Fam via OfficeKB.com Excel Discussion (Misc queries) 5 March 24th 06 05:58 PM
Extracting Numeric Data from a Delimited Text String [email protected] Excel Worksheet Functions 5 February 10th 06 10:29 PM
Extracting numeric values from string RJF Excel Worksheet Functions 3 January 5th 05 10:48 PM


All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"