View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Efficient way to drtermine if a string contains digits?

10 thousand, running on a string variable in a VBA Sub, not on a worksheet
range.

RBS

"Ron Rosenfeld" wrote in message
...
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