afterthought
New Member
- Joined
- Jun 13, 2011
- Messages
- 2
VBA in Excel 2011 for Mac;
I am trying to reconcile a sum with its members. I assigned a variable to collect the sum of the members and an other variable to the sum itself.All numbers entered in the cells have 2 decimals.
The problem: When I use the "built in functions" in Excel, the Closing balance reconciles perfectly with the (Opening balance+credit-debit). When I am trying to use VBA (code enclosed), the two variables are UNEQUAL. WHen I multiply the difference, I see that at higher decimal numbers somehow there is a difference-but I don't know how to correct it. I don't want more than 2 decimal precision. I didn't seem to have this problem before Excel 2011.
Please advise.Thanks
I am trying to reconcile a sum with its members. I assigned a variable to collect the sum of the members and an other variable to the sum itself.All numbers entered in the cells have 2 decimals.
The problem: When I use the "built in functions" in Excel, the Closing balance reconciles perfectly with the (Opening balance+credit-debit). When I am trying to use VBA (code enclosed), the two variables are UNEQUAL. WHen I multiply the difference, I see that at higher decimal numbers somehow there is a difference-but I don't know how to correct it. I don't want more than 2 decimal precision. I didn't seem to have this problem before Excel 2011.
Please advise.Thanks
HTML:
Sub Reconcile()
Dim sngSumOfMembers As Single
Dim sngTheResult As Single
Dim strMessage As String
Worksheets("Sheet1").Select
'This is the Old Balance
Range("FC1").Select
sngSumOfMembers = sngSumOfMembers + ActiveCell.Value
'These are the Debit items
Range("A2").Select
sngSumOfMembers = sngSumOfMembers - ActiveCell.Value
Range("A3").Select
sngSumOfMembers = sngSumOfMembers - ActiveCell.Value
Range("A4").Select
sngSumOfMembers = sngSumOfMembers - ActiveCell.Value
Range("A5").Select
sngSumOfMembers = sngSumOfMembers - ActiveCell.Value
Range("A6").Select
sngSumOfMembers = sngSumOfMembers - ActiveCell.Value
'This a Credit entry
Range("B7").Select
sngSumOfMembers = sngSumOfMembers + ActiveCell.Value
'Closing Balance
Range("C8").Select
strTheResult = ActiveCell.Value
If (sngSumOfMembers - sngTheResult) = 0 Then
strMessage = MsgBox("They are the SAME")
Else
strMessage = MsgBox("They are DIFFERENT")
End If
strMessage = MsgBox(((sngSumOfMembers - sngTheResult) * 1000000000))
End Sub