Beginner:simple VBA problem I can't resolve

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

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
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
The problem in your code is at thes lines

Range("C8").Select
strTheResult = ActiveCell.Value

If (sngSumOfMembers - sngTheResult) = 0 Then

you are using sngTheResult and it should be strTheResult

Try compiling your code before you run it
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top