Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 68
Default Find the First Digit in a Text String

I remember building my own functions way back in Excel 4, but it's been so
long since I've delved that deeply into Excel that my more advanced skills
have atrophied almost to the vanishing point. Too bad, because I really did
use to be a wizard at this stuff. I'm now starting an effort to get back to
that point.

Thanks for reminding me that custom functions can be built. I have worked
with VBA in the past (another one of those atrophying skills) so hopefully
it won't take too long for that knowledge to come back.

--Tom

"macropod" wrote in message
...
Hi Thomas,

You could build your own function to do this. For example:
Function FindDigit(Str As String) As Integer
Dim Pos As Integer, i As Integer
For i = 0 To 9
If InStr(Str, i) 0 Then
If Pos 0 Then
Pos = Application.WorksheetFunction.Min(Pos, InStr(Str, i))
Else
Pos = InStr(Str, i)
End If
End If
Next
FindDigit = Pos
End Function

If you place the above function into a standard vba module for the
workbook, you can use a formula like:
=FindDigit(A1)
to retrieve the first digit's position, or '0' if there are no digits in
the string.

--
Cheers
macropod
[Microsoft MVP - Word]


"Thomas M." wrote in message
...
That works great. I'm a little surprised that there doesn't appear to be
a built-in function for this. I was expecting, for example, something
like a variation on the FIND or SEARCH functions that would essentially
direct the function to return the position of the first digit in a string
value.

In my particular situation the text string will always contain a number,
but writing formulas to cover as many situations as is reasonably
possible is always the best approach.

Thanks for the help.

--Tom

"Ken Wright" wrote in message
...
Does assume though that there actually is a number in there somewhere.
If there isn't then an erroneous answer will be returned. Likewise if
the cell were blank, a 1 will be returned.

=IF(MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"012345678 9"))LEN(A1),0,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1 &"0123456789")))

Will cover all eventualities I think.

Regards
Ken.........................


"macropod" wrote in message
...
Hi Thomas,

Try:
=MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789") )
where the string you're testing is in A1.

--
Cheers
macropod
[Microsoft MVP - Word]


"Thomas M." wrote in message
...
Excel 2007

Is there a way to find the position of the first digit within a text
string?

--Tom




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 to Find Specific Text in a Text String Confused_in_Houston[_2_] Excel Discussion (Misc queries) 2 January 26th 09 08:17 PM
Change a 1,2,3 or 4 digit number to a 6 character text string Steve D Excel Worksheet Functions 3 March 28th 08 08:14 PM
Search, find or lookup defined text in text string zzxxcc Excel Worksheet Functions 9 September 6th 07 09:37 PM
can you find specific text in a string ignoring any other text chriscp Excel Discussion (Misc queries) 1 September 18th 05 09:54 PM
How to find if a string starts with a digit galsaba Excel Worksheet Functions 1 March 4th 05 06:01 PM


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