View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
[email protected] angst987@gmail.com is offline
external usenet poster
 
Posts: 2
Default I'm getting unwanted rounding to integer for an average of rangeof cells.

ahhhhhhh... I overlooked the fact that Long does not include decimals =P

Thanks!

Well, duh!, whadaya think type Long is?

Define rangeavg as type Double, as follows:

Dim rangeavg As Double

By the does not "maintain" the number of decimal places; that is, it is not
limited to 3 decimal places.

If you want to force rounding to 3 decimal places, you might do this one of
two ways:

rangeavg = Round(WorksheetFunction.Average(Range(n1 & o1 & ":" & n1 &
o2)),3)

rangeavg = WorksheetFunction.Round(WorksheetFunction.Average( Range(n1 & o1 &
":" & n1 & o2)),3)

There is a subtle difference between VBA Round and Excel Round. It is
demonstrated by the following example:

MsgBox Round(1.2345,3) & vbNewLine & WorksheetFunction.Round(1.2345,3)