Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 477
Default Format Function Output to numeric (#,###.00)

The following UDF works great except it rounds to $1,234.00 versus $1,234.56.
How can I get the pennies to show?

Function SumByColor(CellColor As Integer, SumRange As Range) As Long
Dim MyCell As Range
Dim myTotal As Double
For Each MyCell In SumRange
If MyCell.Interior.ColorIndex = CellColor Then
myTotal = WorksheetFunction.Sum(MyCell) + myTotal
End If
Next MyCell
SumByColor = myTotal
End Function
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 389
Default Format Function Output to numeric (#,###.00)

Change the Function's return datatype to Double from Long. Long is an
integer datatype, which is truncating the summed values. Actually in your
example it should round up to 1235, but I assume you concocted that example
and that's not a real one.


"Jim May" wrote in message
...
The following UDF works great except it rounds to $1,234.00 versus
$1,234.56.
How can I get the pennies to show?

Function SumByColor(CellColor As Integer, SumRange As Range) As Long
Dim MyCell As Range
Dim myTotal As Double
For Each MyCell In SumRange
If MyCell.Interior.ColorIndex = CellColor Then
myTotal = WorksheetFunction.Sum(MyCell) + myTotal
End If
Next MyCell
SumByColor = myTotal
End Function



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 477
Default Format Function Output to numeric (#,###.00)

Never mind - Not until after I posted the query did I see that it is Originally
designed to out put as LONG versus Double << Changed and everythings OK
Sorry,,


"Jim May" wrote:

The following UDF works great except it rounds to $1,234.00 versus $1,234.56.
How can I get the pennies to show?

Function SumByColor(CellColor As Integer, SumRange As Range) As Long
Dim MyCell As Range
Dim myTotal As Double
For Each MyCell In SumRange
If MyCell.Interior.ColorIndex = CellColor Then
myTotal = WorksheetFunction.Sum(MyCell) + myTotal
End If
Next MyCell
SumByColor = myTotal
End Function

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
VBA - Function Output Jeff Excel Discussion (Misc queries) 2 March 30th 07 07:53 PM
Combo Box - format output as time Robert Mark Bram Excel Discussion (Misc queries) 1 December 5th 05 12:30 AM
Change number (in text format) to numeric format Pam Excel Discussion (Misc queries) 5 October 24th 05 07:45 PM
format cell from data input to output form Brad Stevenson Excel Worksheet Functions 2 May 19th 05 06:04 PM
HOW CAN I SHOW OUTPUT IN FEET INCH FORMAT rich New Users to Excel 2 May 8th 05 06:01 AM


All times are GMT +1. The time now is 06:19 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"