View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Why is excel rounding my numbers in VBA?

Hi,

Am Sun, 10 Feb 2013 18:26:55 +0000 schrieb nappyjim:

Im very new to VBA and wouldent even say I know the basics, I pretty
much took something that worked and tried to modify it and it doesnt
work quite right.

I have a VBA sheet, code seen below. When I input 3 into a cell, I
expect the cell next to it to show 36.88, as the VBA says. But instead,
it rounds its and show 38. I have the cell setup to show 2 decimal
places.

Function StateAllowance(pVal As String) As Long

^^^^^^^^^^
try:

Function StateAllowance(pVal As Integer) As Double
Select Case pVal
Case 0
StateAllowance = 50
Case 1
StateAllowance = 45.96
Case 2
StateAllowance = 41.92
Case 3
StateAllowance = 36.88
Case 4
StateAllowance = 33.85
Case 5
StateAllowance = 29.81
Case 6
StateAllowance = 25.77
Case 7
StateAllowance = 21.73
Case 8
StateAllowance = 17.69
Case 9
StateAllowance = 13.65
Case 10
StateAllowance = 9.62
Case Else
StateAllowance = 50
End Select
End Function


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2