Solved

How to hold currency without rounded in VBA

Posted on 2016-10-05
4
44 Views
Last Modified: 2016-10-05
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

0
Comment
Question by:elm9999
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41830548
You are positively rounding your values to integers:

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

so that's why.

/gustav
1
 

Author Comment

by:elm9999
ID: 41830575
But doesn't work

the nMontoCurrency must have 68.76 but displays 69
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41830587
Please, how do you imagine that to happen when you have declared nMonto as Integer?

Even if you change it to Currency, you round the values to integers with CInt.

So the rounding doesn't "just happen", you specifically twice have coded it so.

/gustav
0
 

Author Comment

by:elm9999
ID: 41830718
Thank you Gustav,

You right, I alredy fix it.
 :)
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now