当具有单元格值的assigne变量时,值出错

时间:2016-02-20 16:42:57

标签: excel excel-vba vba

Dim PtDnr As Single   
Dim TxDnr As Single
GrsDnr AsDim  Single
Dim AmntDnr As Single   
Dim Jour As Integer
Dim I As Integer

Jour = 7



PtDnr = 2256.03                   'trhough 2 loops, the amount is correct

PtDnr = 0

For I = 35 To 40
    PtDnr = PtDnr + Sheets(1).Cells(Jour, I)
Next
For I = 47 To 54
    PtDnr = PtDnr + Sheets(1).Cells(Jour, I)
Next

TxDnr = Sheets(1).Cells(Jour, 32) ' This Cell has a Value of 167.11 "
NtDnr = Sheets(1).Cells(Jour, 33) ' This Cell Has a value of 2088.92
GrsDnr = TxDnr + NtDnr            ' Give me 2256.03, this amount is correct

AmntDnr = GrsDnr - PtDnr          ' Give me 2.441406E.04 wich is wrong                                  

我逐个检查了细胞并将它们设为12位小数,在前2位之后,所有位于" 0"例如:167.110000000000 我做错了什么,我彻夜不眠,尝试了几种可能性,但无法搞清楚。 谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

尝试使用数据类型Double而不是Single。

虽然我不明白,如果我们看不到那些被纳入这些计算的价值,那么任何人都应该知道出了什么问题。