Adding as Single with .value not adding correctly

youcanreachtrevor

New Member
Joined
May 17, 2018
Messages
5
Having trouble googling this querry as the Variable name Single is very common.
Basically I have code that looks to see if the value in the cell is non zero, and if it is non zero then I add my variable (obtained elsewhere) to the existing .vale from the cell.
But somehow the adding isn't working. my variable is declared publically in the Sub, the code below is running within a Private Function initiated from a User Form.
I see for example 34.07 + 44.05 = 78.1125 or something like that...?
Any help is appreciated.
Thanks


Code:
Public Sub Qin_Click()
Dim QINCell As Single
Dim Interim As Single


If NISSCADactuals.Range("E12").Value = "" Then
QINCell = 0
Else: QINCell = NISSCADactuals.Range("E12").Value
End If
MsgBox ("TotalDebitNum: " & TotalDebitNum & " | QINCell: " & QINCell)
NISSCADactuals.Range("E12").Value = TotalDebitNum + QINCell
MsgBox (NISSCADactuals.Range("E12").Value)
Call CreditDebitIteration


End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Please post the code you are using the declare variable TotalDebitNum and describe in which code module that is placed.
 
Upvote 0
I suggest you use Double not Single, since that’s how Excel stores numeric cell values and you can get small conversion errors. Looking at the numbers you mention, I suspect it’s more of a difference between the formatted cell values and their actual values.
 
Upvote 0
Amazing, Thanks RoryA. I changed all of the Singles to Doubles and everything is adding properly now. I saw that Singles were more efficient in storing numbers, but didnt realize that the values in the excel sheet were stored as doubles. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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