请点击链接查看我的图片
这是我的代码。我不明白为什么它总是错误,只有十进制数。我该怎么办?
Sub calcu()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim g1 As Double
Dim g2 As Double
Dim hdp As Double
Dim ts1 As Double
Dim ts2 As Double
Application.ScreenUpdating = False
a = Cells(Rows.Count, "C").End(xlUp).Row
For b = 1 To a
If IsNumeric(Cells(b, "C").Value) Then
hdp = Cells(b, "G")
ts1 = Cells(b, "L")
ts2 = Cells(b, "M")
t1 = Cells(b, "F")
t2 = Cells(b, "H")
g1 = ts1 - hdp
g2 = ts2 - hdp
v1 = 1.72
v2 = 2.1
v3 = 1.9
v4 = 1.8
v5 = 2
If InStr(t1, "K") And g1 < ts2 Then
Cells(b, "J") = "0"
ElseIf InStr(t1, "K") And g1 = ts2 Then
Cells(b, "E") = 1
Cells(b, "J") = 1
ElseIf InStr(t2, "K") And g2 < ts1 Then
Cells(b, "E") = "0"
ElseIf InStr(t2, "K") And g2 = ts1 Then
Cells(b, "E") = 1
Cells(b, "J") = 1
Else
Cells(b, "E") = "error"
Cells(b, "J") = "error"
End If
End If
Next
Application.ScreenUpdating = True
End Sub
答案1
如果您指的是为什么您会得到error
,这与小数无关。
您对第 2 行的测试是执行5
(列 L) - 1.5
(列 G),结果等于 3.5。然后测试该结果是否小于 1,或等于 1 (列 M)。结果不是,所以您得到的是error
。
测试一直失败到 H 列中出现字母 G 的地方,因为最终得到的数字大于正在测试的 M 列中的数字。
由于我不知道您要做什么或结果应该是什么,我无法进一步帮助您,但失败的原因不是小数,而是实际上按照您说的进行了精确的测试,并得出了正确的结果。