Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Extract Only Number From A String


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default Extract Only Number From A String

or try this 1 change 100 rows
mark the first 1 and run macro
numbers stay and rest disaper

Sub koverter()

Dim i, j, x, Indhold, tal

For i = 1 To 100
Indhold = ActiveCell.Value
x = Len(Indhold)
For j = 1 To x
If IsNumeric(Mid(Indhold, j, 1)) Then tal = tal & Mid(Indhold, j, 1)
Next
ActiveCell.Offset(0, 0).Value = tal
tal = ""
ActiveCell.Offset(1, 0).Activate
Next
ActiveCell.End(xlUp).End(xlUp).Activate

End Sub

by the way, vhy cant i start a new question?
i tryed click on New and select Question, but nothing happens?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Extract Only Number From A String

On Thu, 25 May 2006 23:44:26 -0500, lehainam
wrote:


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


You could download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr/ (which will also give you acess to many other useful
functions) and then use this Regular Expression formula (with your string in
A1):

=REGEX.SUBSTITUTE(A1,"\D")

The formula substitutes <nothing for everything in A1 that is not a digit.


--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
EXTRACT NUMBER FROM STRING aRJUN SINGH RAWAT SINGH SRAWAT TATDT Charts and Charting in Excel 1 July 24th 09 08:23 AM
Extract number from text/number string.. nastech Excel Discussion (Misc queries) 5 July 5th 06 11:21 PM
How to extract the Number from a String johnbest New Users to Excel 3 December 19th 05 06:23 PM
Extract 10 digit number from string R. Choate Excel Programming 20 October 27th 05 10:47 PM
Extract 2, 3, 4 or 5-digit number from string Jim[_55_] Excel Programming 2 June 6th 05 06:48 PM


All times are GMT +1. The time now is 03:23 AM.

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

About Us

"It's about Microsoft Excel"