Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Extract numbers from text

Hi
I have a cell with a sentence in text and numbers in between. Is there a
formular so that if I write the formular in B1, it will give me all the
numbers or give me only the text og A1 ?
Thanks
--
Therese
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Extract numbers from text

Here are a couple of User Defined Functions you can use.

Public Function PullText(rngTemp As Range)
Dim strTemp As String

For i = 1 To Len(rngTemp.Value)
If (Asc(Mid(rngTemp.Value, i, 1)) <= 47 Or
Asc(Mid(rngTemp.Value, i, 1)) = 58) Then
strTemp = strTemp & Mid(rngTemp.Value, i, 1)
End If
Next i
PullText = strTemp
End Function

Public Function PullNumbers(rngTemp As Range)
Dim strTemp As String

For i = 1 To Len(rngTemp.Value)
If (Asc(Mid(rngTemp.Value, i, 1)) = 48 And
Asc(Mid(rngTemp.Value, i, 1)) <= 57) Then
strTemp = strTemp & Mid(rngTemp.Value, i, 1)
End If
Next i
PullNumbers = strTemp
End Function

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Extract numbers from text

hHi Kletcko
Thanks a lot for you help, I will see if I can use it, and ten efter that I
will go back to "general questions" where I belong. A bit too tough for me,
but thanks for your time.
--
Therese


"Kletcho" skrev:

Here are a couple of User Defined Functions you can use.

Public Function PullText(rngTemp As Range)
Dim strTemp As String

For i = 1 To Len(rngTemp.Value)
If (Asc(Mid(rngTemp.Value, i, 1)) <= 47 Or
Asc(Mid(rngTemp.Value, i, 1)) = 58) Then
strTemp = strTemp & Mid(rngTemp.Value, i, 1)
End If
Next i
PullText = strTemp
End Function

Public Function PullNumbers(rngTemp As Range)
Dim strTemp As String

For i = 1 To Len(rngTemp.Value)
If (Asc(Mid(rngTemp.Value, i, 1)) = 48 And
Asc(Mid(rngTemp.Value, i, 1)) <= 57) Then
strTemp = strTemp & Mid(rngTemp.Value, i, 1)
End If
Next i
PullNumbers = strTemp
End Function


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Extract numbers from text

You would copy these into a module in your workbook (alt-F11 to get to
the visual basic editor and then Insert - Module to get a module.
Paste the code in the white area.)

Then in a cell in your workbook you would refer to the formula like any
other default excel formula:

=PullNumbers(A1)

or

=PullText(A1)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Extract numbers from text

On Tue, 18 Apr 2006 09:24:02 -0700, Therese
wrote:

Hi
I have a cell with a sentence in text and numbers in between. Is there a
formular so that if I write the formular in B1, it will give me all the
numbers or give me only the text og A1 ?
Thanks


Another option would be to download and install Longre's free morefunc.xll
add-in from http://xcell05.free.fr/.

This can be distributed freely with your workbook.

You can then use the regular expression formulas:

=REGEX.SUBSTITUTE(A1,"\D") to extract the numbers and

=REGEX.SUBSTITUTE(A1,"\d") to extract everything that is not a number.

This will work unless your sentence has more than 255 characters. If it does,
similar solutions using VBA regular expressions can be devised.


--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
HOW DO I EXTRACT NUMBERS FROM TEXT STRING AndyF Excel Discussion (Misc queries) 7 August 14th 08 02:37 PM
how to extract numbers from imported cell with text and numbers? jyin Excel Discussion (Misc queries) 3 March 28th 07 01:14 PM
Extract numbers from cell with Text and Numbers wiredwrx New Users to Excel 3 April 18th 06 10:57 PM
How do I extract numbers from a cell with both text and numbers? SHANNON Excel Worksheet Functions 8 December 2nd 05 02:31 AM
extract numbers from cell containing text & numbers [email protected] Excel Worksheet Functions 1 November 14th 05 07:04 AM


All times are GMT +1. The time now is 02:54 PM.

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"