LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #21   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,934
Default Need formula to extract a numeric value from a free-format text

My last message had the wrong opening sentence (it was meant for another
message I was working on). This is what I meant to post...

The function I posted does not work as I had indicated... it finds the last
7-digit number, not the first. Here is the corrected code (plus I added the
missing *MISSING* indicator)...

Function First7DigitNumber(S As String) As String
Dim X As Long
For X = 1 To Len(S)
If Mid(" " & S & " ", X, 9) Like "[!0-9]#######[!0-9]" Then
First7DigitNumber = Mid(S, X, 7)
Exit Function
End If
Next
First7DigitNumber = "*MISSING*"
End Function

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
I am still not sure if the OP wanted the 7-digit number to stand alone (as
a "word") or not, so I just went for the first isolated 7 digits in a
row...

Function First7DigitNumber(S As String) As String
Dim X As Long
For X = 1 To Len(S)
If Mid(" " & S & " ", X, 9) Like "[!0-9]#######[!0-9]" Then
First7DigitNumber = Mid(S, X, 7)
Exit Function
End If
Next
First7DigitNumber = "*MISSING*"
End Function

--
Rick (MVP - Excel)


"Ron Rosenfeld" wrote in message
...
On Sat, 18 Jul 2009 10:54:43 -0400, "Rick Rothstein"
wrote:

Function First7DigitNumber(S As String) As String
Dim X As Long
For X = 1 To Len(S)
If Mid(" " & S & " ", X, 9) Like "[!0-9]#######[!0-9]" Then
First7DigitNumber = Mid(S, X, 7)
End If
Next
End Function


I note that given the following modification of the OP's test string:

"User requested authority of emergency ID for reason NHUSER1234567
Restore
of object to library LEVEL2 under remedy 61074317. 06/04/09 17:46 QPGMR"

your routine returns 1234567 whereas my UDF returns "MISSING" since
there are
no seven digit words.

(Lori's formulas return 1074317)

--ron



 
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
Find text in free-format text field Eric_NY Excel Discussion (Misc queries) 5 May 27th 09 07:31 PM
Extract just numeric part of mixed text/number entry? Heidi Excel Worksheet Functions 7 June 1st 06 07:33 PM
only extract numeric value from alpha numeric cell Fam via OfficeKB.com Excel Discussion (Misc queries) 5 April 26th 06 06:49 PM
Change number (in text format) to numeric format Pam Excel Discussion (Misc queries) 5 October 24th 05 07:45 PM
Everytime I need to format cells or text, Excel 2003 takes a lot of time or free Florimar Agostini via OfficeKB.com Excel Discussion (Misc queries) 1 April 1st 05 06:29 AM


All times are GMT +1. The time now is 04:56 AM.

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"