View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Extract Only Number From A String

Hi Nam,

Try:

'=============
Public Function DigitsOnly(sStr As String) As Variant
Dim oRegExp As Object

Set oRegExp = CreateObject("VBScript.RegExp")

With oRegExp
.IgnoreCase = True
.Global = True
oRegExp.Pattern = "\D"

DigitsOnly = CLng(.Replace(sStr, vbNullString))
End With
End Function
'<<=============

A1: 589as56
B1 = DigitsOnly(A1) == 58956


---
Regards,
Norman



"lehainam" wrote in
message ...

Dear all,

In Excel, is there any function that I can get number only in string
that has number & text

Ex: in cell A1 589as56
I would like to get the string 58956 only

Thank you very much

Nam


--
lehainam
------------------------------------------------------------------------
lehainam's Profile:
http://www.excelforum.com/member.php...o&userid=18615
View this thread: http://www.excelforum.com/showthread...hreadid=545735