View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Counting Digits in a string

Public Function numLen(rng as Range)
Dim sStr as String, i as Long
sStr = Range("A1").Value
for i = 1 to len(sStr)
if isnumeric(Mid(sStr,i,1)) Then
numlen = len(sStr)- i + 1
exit for
end if
Next
End Function

Demo'd from the immediate Window:
Range("B9").Value = "Consider This Example489"
? numLen(Range("B9"))
3
? Right(Range("B9"),numlen(Range("B9")))
489


or are you looking for a worksheet formula solution?

--
Regards,
Tom Ogilvy

"bw" wrote in message
...
I want to know how many digits (numbers) there are at the end of a string,
so that I may move them elsewhere.
For example:
A1= "Consider This Example489".
This example has three digits.
Because I know A1 has 3 digits (after someone explains how to compute it),
then B1=Right(A1,3)=489.

Thanks,
Bernie