Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
bw bw is offline
external usenet poster
 
Posts: 74
Default Counting Digits in a string

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



  #2   Report Post  
Posted to microsoft.public.excel.programming
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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Counting Digits in a string

This will extract the digits at the end

=MID(A1,MIN(IF(ISERROR(1*(MID(A1,ROW(INDIRECT("A1: A"&LEN(A1))),1))),
255,ROW(INDIRECT("A1:A"&LEN(A1))))),99)

which is an array, so commit with Ctrl-Shift-Enter

--

HTH

RP
(remove nothere from the email address if mailing direct)


"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





  #4   Report Post  
Posted to microsoft.public.excel.programming
bw bw is offline
external usenet poster
 
Posts: 74
Default Counting Digits in a string

Thank you both, Tom and Bob.
I wanted a spreadsheet solution, but I didn't know how to do it with code
either.
I don't understand the spreadsheet solution as provided by Bob, but it does
work. I'll have to see if I can figure out what you have done here to make
this work.

Thank you both again.
Bernie

"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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Counting Digits in a string

Put simply, my formula looks at each character in turn and multiplies it by
1. This will error if is not a number, so it easily extracts the numeric
values.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"bw" wrote in message
...
Thank you both, Tom and Bob.
I wanted a spreadsheet solution, but I didn't know how to do it with code
either.
I don't understand the spreadsheet solution as provided by Bob, but it

does
work. I'll have to see if I can figure out what you have done here to

make
this work.

Thank you both again.
Bernie

"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









  #6   Report Post  
Posted to microsoft.public.excel.programming
bw bw is offline
external usenet poster
 
Posts: 74
Default Counting Digits in a string

Thanks for the explanation Bob. It helps me to understand it somewhat, but
not enough to make a change.
The formula does not work when there are embedded numbers.
For example, "ABC 123 DEF 9".
I only want to know how many numbers are at the END of the string...in this
case 1 (the number 9).

Got a fix?

Thanks,
Bernie

"Bob Phillips" wrote in message
...
Put simply, my formula looks at each character in turn and multiplies it
by
1. This will error if is not a number, so it easily extracts the numeric
values.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"bw" wrote in message
...
Thank you both, Tom and Bob.
I wanted a spreadsheet solution, but I didn't know how to do it with code
either.
I don't understand the spreadsheet solution as provided by Bob, but it

does
work. I'll have to see if I can figure out what you have done here to

make
this work.

Thank you both again.
Bernie

"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









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
This cell contains a date string rep. with only 2 digits for the y jdungan Excel Discussion (Misc queries) 5 June 5th 09 05:40 PM
counting Row() digits? stew Excel Discussion (Misc queries) 3 January 16th 09 03:29 PM
Convert string of digits into a date Scott Lolmaugh Excel Worksheet Functions 1 February 23rd 06 09:43 PM
Zero appears at the end of a string of 16 digits. Two zeros after cawhitaker Excel Discussion (Misc queries) 4 November 2nd 05 06:43 PM
How do I specific digits in a long string? PhilGTI Excel Discussion (Misc queries) 2 February 21st 05 05:21 PM


All times are GMT +1. The time now is 08:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"