
大神 帮我看下 vba中 on error goto的问题
Sub循环()OnErrorGoTo100Fori=2To8DoUntili>8Sheet1.Cells(i,4)=Sheet1.Cells(i,2)+Sheet1.Ce...
Sub 循环()On Error GoTo 100For i = 2 To 8 Do Until i > 8 Sheet1.Cells(i, 4) = Sheet1.Cells(i, 2) + Sheet1.Cells(i, 3) GoTo d100: MsgBox "对不起,错误发生在第" & i & "行" Loopd:Next iEnd Sub代码是为了算总分,当有未考的时候,不算总分,并提示信息,帮忙看下,运行到第五行要算陈6的时候,提示我 错误类型,13
提示错误 13 展开
提示错误 13 展开
展开全部
你可真棒,能用两句代码写出这么混乱的结构,好像生怕别人不知道你会用goto和on error。
你那报错算幸运的了,不报错的话就凭你那do loop也是死循环。
Sub 循环()
On Error GoTo Err_Handle:
Dim Err_Info As String: Err_Info = ""
Dim i As Byte: i = 0
For i = 2 To 8
Cells(i, 4) = Cells(i, 2) + Cells(i, 3)
Next i
If Err_Info <> "" Then MsgBox ("错误出现在第" & Err_Info & Chr(10) & "行")
Exit Sub
Err_Handle:
Err_Info = Err_Info & Chr(10) & i
Resume Next
End Sub
展开全部
Sub 循环()
For i = 2 To 8
With Sheet1
If IsNumeric (.Cells(i, 2)) AND IsNumeric (.Cells(i, 3)) Then
.Cells(i,4) = .Cells(i,2) + .Cells(i,3)
End If
End With
Next i
End Sub
For i = 2 To 8
With Sheet1
If IsNumeric (.Cells(i, 2)) AND IsNumeric (.Cells(i, 3)) Then
.Cells(i,4) = .Cells(i,2) + .Cells(i,3)
End If
End With
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
goto的标示要以字母打头吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询