Solved

How to hold currency without rounded in VBA

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

758 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

19 Experts available now in Live!

Get 1:1 Help Now