Link to home
Start Free TrialLog in
Avatar of Member_2_6479049
Member_2_6479049

asked on

How to hold currency without rounded in VBA

Hello experts,

I made a report in VBA where I need to hold money but the result always is rounded, for example:
If the source data is 528.85 , the report shows 529.

Could you please help me in this matter?
 
Dim cAcumulaCheques As String
Dim cAcumulaMonto As String
Dim nMonto As Integer
Dim nMontoCurrency As Currency
Dim nSumaTotalMonto As Currency


    For I = 3 To wsSource.Cells(Rows.Count, "A").End(xlUp).Row
        If wsSource.Cells(I, 4).Value = "" Then
            GoTo Nexts
        Else
            If Val(wsSource.Cells(I, 1)) = Val(nDia) And Val(wsSource.Cells(I, 2)) = Val(nMes) And Val(wsSource.Cells(I, 3)) = Val(nAno) Then
                If Trim(wsSource.Cells(I, 15) <> "") Then
                    cAcumulaCheques = Trim(wsSource.Cells(I, 15))
                    nMonto = CInt(wsSource.Cells(I, 16))
                    nMontoCurrency = Format(nMonto, "Currency")
                    cAcumulaMonto = nMontoCurrency
                    nSumaTotalMonto = (nSumaTotalMonto + nMonto)
                End If

Open in new window

Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

You are positively rounding your values to integers:

nMonto = CInt(wsSource.Cells(I, 16))
nMontoCurrency = Format(nMonto, "Currency")

so that's why.

/gustav
Avatar of Member_2_6479049
Member_2_6479049

ASKER

But doesn't work

the nMontoCurrency must have 68.76 but displays 69
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Gustav,

You right, I alredy fix it.
 :)