Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 58
Default How can I search for a string of numeric digits within a text stri

I've got some cells containing text. Somewhere inside each cell is a 6-digit
number, though not necessarily in the same location in each cell. (A few
cells may be missing the number.)

Is there some way using to find and extract the number using built-in
functions? If not, how would I do it in a user-defined function?

Thanks.


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default How can I search for a string of numeric digits within a text stri

Hi,

Try this

=LOOKUP(10^23,--MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"012345 6789")),ROW(INDIRECT("1:"&LEN(A1)))))

This is an array formula which must be entered with 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 ranges
'then you must re-enter as An array

Mike



"Eric_NY" wrote:

I've got some cells containing text. Somewhere inside each cell is a 6-digit
number, though not necessarily in the same location in each cell. (A few
cells may be missing the number.)

Is there some way using to find and extract the number using built-in
functions? If not, how would I do it in a user-defined function?

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default How can I search for a string of numeric digits within a text stri

Since you are always looking for a 6-digit number, this formula will do what
you ask...

=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456 789")),6)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
I've got some cells containing text. Somewhere inside each cell is a
6-digit
number, though not necessarily in the same location in each cell. (A few
cells may be missing the number.)

Is there some way using to find and extract the number using built-in
functions? If not, how would I do it in a user-defined function?

Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default How can I search for a string of numeric digits within a text stri

Try this UDF:

Function numit(r As Range) As Double
Dim s As String, s2 As String, c As String
s2 = ""
s = r.Value
l = Len(s)
k = 0
For i = 1 To l
c = Mid(s, i, 1)
If c Like "#" Then
s2 = s2 & c
k = k + 1
If k = 6 Then Exit For
Else
s2 = ""
k = 0
End If
Next
numit = --s2
End Function

so if A1 contains:
a12dfg476492hfsjfsfhwkfhkdsh6823643274632

then

=numit(A1) will display 476492
the 12 is ignored as is the junk at the end
--
Gary''s Student - gsnu200828


"Eric_NY" wrote:

I've got some cells containing text. Somewhere inside each cell is a 6-digit
number, though not necessarily in the same location in each cell. (A few
cells may be missing the number.)

Is there some way using to find and extract the number using built-in
functions? If not, how would I do it in a user-defined function?

Thanks.


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 58
Default How can I search for a string of numeric digits within a text

The 6-digit number is not the only numeric data in the cell.

For example, it might look like "9/2/2008 07:14 RNAJRED requested authority
of RSQEMERG for reason RNAJRED RSQEMERG RBM holiday-restore file
937016. QPGMR"

I need a formula that will find the 6-digit number only.

Thanks.


"Rick Rothstein" wrote:

Since you are always looking for a 6-digit number, this formula will do what
you ask...

=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456 789")),6)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
I've got some cells containing text. Somewhere inside each cell is a
6-digit
number, though not necessarily in the same location in each cell. (A few
cells may be missing the number.)

Is there some way using to find and extract the number using built-in
functions? If not, how would I do it in a user-defined function?

Thanks.






  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default How can I search for a string of numeric digits within a text

You failed to mention in your original posting that your "text" could
contain other numbers besides the one you were looking for. It's kind of
hard to give you the solution you want if you don't tell us all of the
parameters we need to know. Just out of curiosity, can any of those other
numbers be 6 **or more** digits long? If so, would the number you want to
find always be the last number in the text?

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
The 6-digit number is not the only numeric data in the cell.

For example, it might look like "9/2/2008 07:14 RNAJRED requested
authority
of RSQEMERG for reason RNAJRED RSQEMERG RBM holiday-restore file
937016. QPGMR"

I need a formula that will find the 6-digit number only.

Thanks.


"Rick Rothstein" wrote:

Since you are always looking for a 6-digit number, this formula will do
what
you ask...

=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456 789")),6)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
I've got some cells containing text. Somewhere inside each cell is a
6-digit
number, though not necessarily in the same location in each cell. (A
few
cells may be missing the number.)

Is there some way using to find and extract the number using built-in
functions? If not, how would I do it in a user-defined function?

Thanks.





  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 58
Default How can I search for a string of numeric digits within a text

"can any of those other numbers be 6 **or more** digits long" - don't know,
but for purposes of this exercise, let's assume not.

Thanks for your help.


"Rick Rothstein" wrote:

You failed to mention in your original posting that your "text" could
contain other numbers besides the one you were looking for. It's kind of
hard to give you the solution you want if you don't tell us all of the
parameters we need to know. Just out of curiosity, can any of those other
numbers be 6 **or more** digits long? If so, would the number you want to
find always be the last number in the text?

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
The 6-digit number is not the only numeric data in the cell.

For example, it might look like "9/2/2008 07:14 RNAJRED requested
authority
of RSQEMERG for reason RNAJRED RSQEMERG RBM holiday-restore file
937016. QPGMR"

I need a formula that will find the 6-digit number only.

Thanks.


"Rick Rothstein" wrote:

Since you are always looking for a 6-digit number, this formula will do
what
you ask...

=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456 789")),6)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
I've got some cells containing text. Somewhere inside each cell is a
6-digit
number, though not necessarily in the same location in each cell. (A
few
cells may be missing the number.)

Is there some way using to find and extract the number using built-in
functions? If not, how would I do it in a user-defined function?

Thanks.






  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default How can I search for a string of numeric digits within a text

Then try this User Defined Function (UDF)...

Function FindSixDigitNumber(S As String) As Long
Dim X As Long
For X = 1 To Len(S)
If Mid(S, X, 6) Like "######" Then
FindSixDigitNumber = Mid(S, X, 6)
Exit For
End If
Next
End Function

To install it, press Alt+F11 to get into the VB editor, click Insert/Module
from the VB editor menu bar and copy/paste the above code into the code
windows that appeared. Now, go back to your worksheet and use that function
just like you would any built-in functions. For example,

=FindSixDigitNumber(A1)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
"can any of those other numbers be 6 **or more** digits long" - don't
know,
but for purposes of this exercise, let's assume not.

Thanks for your help.


"Rick Rothstein" wrote:

You failed to mention in your original posting that your "text" could
contain other numbers besides the one you were looking for. It's kind of
hard to give you the solution you want if you don't tell us all of the
parameters we need to know. Just out of curiosity, can any of those other
numbers be 6 **or more** digits long? If so, would the number you want to
find always be the last number in the text?

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
The 6-digit number is not the only numeric data in the cell.

For example, it might look like "9/2/2008 07:14 RNAJRED requested
authority
of RSQEMERG for reason RNAJRED RSQEMERG RBM holiday-restore file
937016. QPGMR"

I need a formula that will find the 6-digit number only.

Thanks.


"Rick Rothstein" wrote:

Since you are always looking for a 6-digit number, this formula will
do
what
you ask...

=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456 789")),6)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
I've got some cells containing text. Somewhere inside each cell is a
6-digit
number, though not necessarily in the same location in each cell. (A
few
cells may be missing the number.)

Is there some way using to find and extract the number using
built-in
functions? If not, how would I do it in a user-defined function?

Thanks.







  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 58
Default How can I search for a string of numeric digits within a text

Thanks. I would probably revise this to "For X = 1 to Len(S) - 5"

Thanks very much for showing me how to create a UDF. My VBA skills are
limited, and I've never been sure of the specifics of how to do it.

"Rick Rothstein" wrote:

Then try this User Defined Function (UDF)...

Function FindSixDigitNumber(S As String) As Long
Dim X As Long
For X = 1 To Len(S)
If Mid(S, X, 6) Like "######" Then
FindSixDigitNumber = Mid(S, X, 6)
Exit For
End If
Next
End Function

To install it, press Alt+F11 to get into the VB editor, click Insert/Module
from the VB editor menu bar and copy/paste the above code into the code
windows that appeared. Now, go back to your worksheet and use that function
just like you would any built-in functions. For example,

=FindSixDigitNumber(A1)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
"can any of those other numbers be 6 **or more** digits long" - don't
know,
but for purposes of this exercise, let's assume not.

Thanks for your help.


"Rick Rothstein" wrote:

You failed to mention in your original posting that your "text" could
contain other numbers besides the one you were looking for. It's kind of
hard to give you the solution you want if you don't tell us all of the
parameters we need to know. Just out of curiosity, can any of those other
numbers be 6 **or more** digits long? If so, would the number you want to
find always be the last number in the text?

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
The 6-digit number is not the only numeric data in the cell.

For example, it might look like "9/2/2008 07:14 RNAJRED requested
authority
of RSQEMERG for reason RNAJRED RSQEMERG RBM holiday-restore file
937016. QPGMR"

I need a formula that will find the 6-digit number only.

Thanks.


"Rick Rothstein" wrote:

Since you are always looking for a 6-digit number, this formula will
do
what
you ask...

=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456 789")),6)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
I've got some cells containing text. Somewhere inside each cell is a
6-digit
number, though not necessarily in the same location in each cell. (A
few
cells may be missing the number.)

Is there some way using to find and extract the number using
built-in
functions? If not, how would I do it in a user-defined function?

Thanks.








  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default How can I search for a string of numeric digits within a text

Thanks. I would probably revise this to "For X = 1 to Len(S) - 5"

LOL... yeah, Len(S) - 5 does make more sense. And, of course, you are most
welcome.

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
Thanks. I would probably revise this to "For X = 1 to Len(S) - 5"

Thanks very much for showing me how to create a UDF. My VBA skills are
limited, and I've never been sure of the specifics of how to do it.

"Rick Rothstein" wrote:

Then try this User Defined Function (UDF)...

Function FindSixDigitNumber(S As String) As Long
Dim X As Long
For X = 1 To Len(S)
If Mid(S, X, 6) Like "######" Then
FindSixDigitNumber = Mid(S, X, 6)
Exit For
End If
Next
End Function

To install it, press Alt+F11 to get into the VB editor, click
Insert/Module
from the VB editor menu bar and copy/paste the above code into the code
windows that appeared. Now, go back to your worksheet and use that
function
just like you would any built-in functions. For example,

=FindSixDigitNumber(A1)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
"can any of those other numbers be 6 **or more** digits long" - don't
know,
but for purposes of this exercise, let's assume not.

Thanks for your help.


"Rick Rothstein" wrote:

You failed to mention in your original posting that your "text" could
contain other numbers besides the one you were looking for. It's kind
of
hard to give you the solution you want if you don't tell us all of the
parameters we need to know. Just out of curiosity, can any of those
other
numbers be 6 **or more** digits long? If so, would the number you want
to
find always be the last number in the text?

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
The 6-digit number is not the only numeric data in the cell.

For example, it might look like "9/2/2008 07:14 RNAJRED requested
authority
of RSQEMERG for reason RNAJRED RSQEMERG RBM holiday-restore file
937016. QPGMR"

I need a formula that will find the 6-digit number only.

Thanks.


"Rick Rothstein" wrote:

Since you are always looking for a 6-digit number, this formula
will
do
what
you ask...

=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456 789")),6)

--
Rick (MVP - Excel)


"Eric_NY" wrote in message
...
I've got some cells containing text. Somewhere inside each cell
is a
6-digit
number, though not necessarily in the same location in each cell.
(A
few
cells may be missing the number.)

Is there some way using to find and extract the number using
built-in
functions? If not, how would I do it in a user-defined function?

Thanks.









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
Remove Numeric from a Text String - Help? Bob Phillips Excel Discussion (Misc queries) 9 September 27th 06 09:25 AM
Formula to extract digits from a text string? [email protected] Excel Worksheet Functions 7 January 15th 06 04:16 AM
Find first numeric value in text string Rbp9ad Excel Worksheet Functions 4 October 15th 05 02:01 AM
Need insert a dash in between last 4 digits in text string Phil Excel Worksheet Functions 3 August 22nd 05 10:48 PM
Search string for alpha or numeric David Excel Worksheet Functions 4 June 8th 05 05:19 PM


All times are GMT +1. The time now is 06:27 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"