View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Efficient way to drtermine if a string contains digits?

On Thu, 30 Aug 2007 20:39:59 -0400, Ron Rosenfeld
wrote:

On Thu, 30 Aug 2007 16:39:20 -0700, "Jim Cone" wrote:


RBS,
Thanks for the info.
Even when "Like" is slower I still like Like. <g
Jim Cone


"RB Smissaert"

wrote in message
Yes, that is the fastest, but of course it doesn't give the position of the
first digit.
Did some timing, running on this string:
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2aaabbbbbbbbb bb3bbb"

Jim 4 msecs
RBS 24 msecs
Ron 5200 msecs

Of course the VBScript method will be a lot faster if the first 3 lines of
code are taken out of the function.
RBS


How many iterations did you time?

And I would guess that my formula solution would be even faster, based on the
time to complete calculations over 65534 cells.

Also, as a small nit, RBS solution does not do what the OP suggested in his
example.

One example would be a function that returns "TRUE" if one or more
characters of its single argument are digits and "FALSE" otherwise.


And Jim's solution (which I really like), returns FALSE for an empty cell.
--ron


Hit send too soon. My formula solution would need to be modified to do that:

=IF(A1<"",NOT(ISNA(LOOKUP(9.9+307,--MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},
A1&"0123456789")),ROW(INDIRECT("1:"&LEN(A1))))))) )
--ron