Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to hold currency without rounded in VBA

Posted on 2016-10-05
4
57 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

791 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