Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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
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
How do I add an integer to an existing integer? Aaron Excel Worksheet Functions 3 December 17th 09 09:46 PM
Create number format for 4 digit integer preceded by zero Headfish Excel Worksheet Functions 6 April 14th 06 08:56 PM
Color a single digit in a mult-digit number cell Phyllis Excel Discussion (Misc queries) 6 November 17th 05 12:46 AM
How do I identify the 7th digit in a 13 digit number, then establi Catherine Excel Worksheet Functions 7 April 4th 05 06:11 PM
When we enter a 16 digit number (credit card) the last digit chan. ceking Excel Discussion (Misc queries) 5 December 8th 04 11:45 PM


All times are GMT +1. The time now is 12:36 PM.

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"