View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld[_3_] Ron Rosenfeld[_3_] is offline
external usenet poster
 
Posts: 12
Default custom round function

On Fri, 16 Jan 2004 21:31:23 -0600, Princess Geek
wrote:

I'm writing a function to change the last integer in a numeric value to
either a 5 or a 9-(replicating a Peachtree function).

The Select case functions is clearly an option, but how do I get the
function to focus on the last integer ? The * doesn't work-

example:
Change 1442 to 1445
1327.55 to 1329



LastDigit = WorksheetFunction.Round(rg, 0) Mod 10

will give you the last digit of a rounded number.

Something like:

======================
Function Round59(rg As Range) As Long
Dim LastDigit As Integer

LastDigit = WorksheetFunction.Round(rg, 0) Mod 10
Round59 = WorksheetFunction.RoundUp(rg / 5, 0) * 5

Round59 = Round59 + (LastDigit 5)

End Function
========================

might do what you are looking for.


--ron