Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA to identify last digit in integer
I need to identify the last digit in a test integer. I presently am about to convert the integer to a string, use Right(TestInteger,1) to extract the last character, then convert that character back to a value. Seems to me I, once again, am probably missing some other painfully obvious and easier means. Any ideas? -- brucemc ------------------------------------------------------------------------ brucemc's Profile: http://www.excelforum.com/member.php...o&userid=32871 View this thread: http://www.excelforum.com/showthread...hreadid=546104 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA to identify last digit in integer
On Fri, 26 May 2006 21:07:59 -0500, brucemc
wrote: I need to identify the last digit in a test integer. I presently am about to convert the integer to a string, use Right(TestInteger,1) to extract the last character, then convert that character back to a value. Seems to me I, once again, am probably missing some other painfully obvious and easier means. Any ideas? TestInteger Mod 10 This seems to work in VBA: ========================== Sub LastDigit() Const Num As Long = 79368412 Debug.Print "Last Digit in " & Num & " is " & _ Num Mod 10 End Sub =========================== --ron |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA to identify last digit in integer
Why convert to string, just test the numeric value itself debug.print right(12345,1) debug.print right(intValue,1) either way works with out converting to a string -- bgeier ------------------------------------------------------------------------ bgeier's Profile: http://www.excelforum.com/member.php...o&userid=12822 View this thread: http://www.excelforum.com/showthread...hreadid=546104 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA to identify last digit in integer
Darn it, and Thank-YOU! I've got to quit taking what MS writes as fact, unless there is a "special" definition they were using for "String" in the description of the RIGHT function... -- brucemc ------------------------------------------------------------------------ brucemc's Profile: http://www.excelforum.com/member.php...o&userid=32871 View this thread: http://www.excelforum.com/showthread...hreadid=546104 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA to identify last digit in integer
Microsoft uses "string" differently depending on what they are trying t say. In code "String" means a string of characters, regardless of how human perceive the characters. Whenever Microsoft uses "string" in a description of a function, the mean whatever they want it to mean, usually it means any type o character -- bgeie ----------------------------------------------------------------------- bgeier's Profile: http://www.excelforum.com/member.php...fo&userid=1282 View this thread: http://www.excelforum.com/showthread.php?threadid=54610 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA to identify last digit in integer
The solution to your specific problem has been identified already.
This is an interesting problem. The number of digits in the integer part of any number is given by: int(1+log(YourNumber)/log(10)) where YourNumber can be an integer or float. Say YourNumber is 1236.45, the last digit is: Debug.Print mid(1236.45,int(1+log(1236.45)/log(10)),1) This can be extended; say, you wanted the last but one digit, the position is: int(1+log(YourNumber)/log(10)) -1 etc.. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I add an integer to an existing integer? | Excel Worksheet Functions | |||
Create number format for 4 digit integer preceded by zero | Excel Worksheet Functions | |||
Color a single digit in a mult-digit number cell | Excel Discussion (Misc queries) | |||
How do I identify the 7th digit in a 13 digit number, then establi | Excel Worksheet Functions | |||
When we enter a 16 digit number (credit card) the last digit chan. | Excel Discussion (Misc queries) |