我得到了没有if"以下代码错误:
Sub test()
Dim Total As Double
Dim Timein As Date
Dim Timeout As Date
a = 2
b = 0
label2: a = 2
For a = 2 To 21
b = a + 1
If a >= 20 Then GoTo label2
Timein = CDate(Cells(a, 1).Value)
Timeout = CDate(Cells(b, 1).Value)
Total = TimeValue(Timeout) - TimeValue(Timein)
Debug.Print Total
Debug.Print Format(Total, "hh:mm:ss")
Cells(a, 4).NumberFormat = "hh:mm:ss"
Cells(a, 4).Value = Total
Debug.Print "Number of hours = " & Total * 24
End If
Next a
End Sub
只有做了If … Then
,才能做End If
。If … Then GoTo
单独存在,不应与End If
匹配。