Hi
First time here and first time to any vba or coding forum. Been programming for 12 years now, mostly in VBA and C and this is the first time I've looked for help.
Its something so simple, yet for some reason I am not getting the results I expect. Hoping some of you could provide some insight.
I have a simple function that breaks down data into "Pie Slices" - percentages of the whole. To ensure I'm not losing information, I created a test to see if my Pie Slices total 100% (or 1). The Code is as follows:
For i = 1 To pCashTran_c
pCashPer(i) = Round(pCashTranArray(i) / pTotalValue, 2)
Test = Test + pCashPer(i)
Next
For i = 1 To pStockTran_c
pStockPer(i) = Round((value * pStockTranArray(i)) / pTotalValue, 2)
Test = Test + pStockPer(i)
Next
The test is:
If Test < 1 Then
answer = MsgBox("Test is less than 1, " & Test, vbOKOnly)
ElseIf Test > 1 Then
answer = MsgBox("Test is greater than 1, " & Test, vbOKOnly)
ElseIf Test = 1 Then
answer = MsgBox("Test is a go", vbOKOnly)
End If
It started out simpler than that as
, but a value of 1 would prompt the msgbox, so I broke it down. Pretty much, a value of 1 may or may not fail the less than test. It is not consistent. I feel that data is being lost, but the rounding of the values should prevent that, shouldn't it?
Bookmarks