Thank you for the information Rick. I did not declare the function as
returning a string because I assumed I was returning numbers and I never
even noticed that the return was right aligned.
Unfortunately I cannot run your elegant code because I am the poor cousin
who only has XL97 - and lucky to have that.
By the time that I was writing the code I had completely forgotten about
the last 7 digits ot fewer - short term memory loss!
--
Regards,
Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings
(e-mail address removed)
Replace @mailinator.com with @tiscali.co.uk
Rick Rothstein (MVP - VB) said:
You should consider declaring your function as returning a String,
otherwise it returns 0 if the cell it references is empty. Oh, and your
function returns all digits after the text... the OP asked for the last 7
or less digits.
Here is my slightly shorter UDF for this question...
Function EndBit(R As Range) As String
Application.Volatile
If R Like "*[0-9]" Then EndBit = StrReverse(Val(StrReverse(Right$(R,
7))))
End Function
Rick
Sandy Mann said:
That's strange, I could have sworn that I tested it and it worked for an
empty cell but it does not.
Change the line:
If r Is Nothing Then Exit Function
to:
If r ="" Then Exit Function
--
HTH
Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings
(e-mail address removed)
Replace @mailinator.com with @tiscali.co.uk
I can't do it in a formula but I may be able to get you one. I'll give
you
a UDF solution and someone will be along in a minute to suggest a
formula
answer. <g>
Copy this Function and paste it into a normal module:
Function EndBit(r As Range)
Application.Volatile
If r Is Nothing Then Exit Function
For x = Len(r) To 1 Step -1
If Asc(Mid(r, x, 1)) > 57 _
Or Asc(Mid(r, x, 1)) < 48 Then
s = x + 1
Exit For
End If
If x = 1 Then s = x
Next x
EndBit = Mid(r, s, 255)
End Function
Then enter in the spreadsheet:
=EndBit(A1)
with the entry in A1 it will return return only the numbers at the end
of
the entry in A1
--
HTH
Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings
(e-mail address removed)
Replace @mailinator.com with @tiscali.co.uk
On Aug 13, 2:45 pm, "Rick Rothstein \(MVP - VB\)"
I am in requirement of a formula for extracting only last seven (or
less) numerical digits from a reference.
Ex -
1 - if A1 consists 112233help573847 - I need "573847".
2 - if A1 consists 112233help573 - I need "573".
3 - if A1 consists 112233help - I need "112233".
4 - if A1 consists 112233 - Ineed "112233".
Do the entries always start off with 6 digits, or did you just take a
short
cut when posting your question?
Rick
I have just taken short cut, but the series will always will be
random.