0

我没有这个问题已经出现了很多次,我已经通读了所有这些,并且之前在我的代码中遇到过这个问题并且能够解决它。

If count > 1 Then
           For Each Match1 In Regex.Execute(text)
           myOtherSheet.Cells(j, 1).Value = WkSht.Cells(r, 2)
           If Macth1 = "" Then
           Exit For
           Else
           myOtherSheet.Cells(j, 2).Value = Match1
           j = j + 1
           Next Match1
           End If

代码在 Next Match1 行给出错误,这通常发生在我忘记关闭循环但这里一切正常时,如果程序无法运行,是否在 INNNER 中退出?

4

3 回答 3

2

错过End If之前Next。注意!!!

正确格式化您的代码应该可以避免这种错误。

于 2013-07-12T10:22:06.673 回答
0

End If在下一场比赛前失踪1

您可以使用 Smart Indenter 插件,这将使代码更具可读性并修复像这样的语法问题。 下载智能压头

If count > 1 Then
    For Each Match1 In Regex.Execute(text)
        myOtherSheet.Cells(j, 1).Value = WkSht.Cells(r, 2)
        If Macth1 = "" Then
            Exit For
        Else
            myOtherSheet.Cells(j, 2).Value = Match1
            j = j + 1
        End If
        Next Match1
    End If
于 2013-07-12T10:23:25.663 回答
0

我在@LS_dev 的回答中补充说,如果你总是使用缩进,那么你更有可能得到所有的End IfNext正确的。

因为您的代码看起来像这样带有缩进:

If Count > 1 Then
    For Each Match1 In Regex.Execute(Text)
        myOtherSheet.Cells(j, 1).Value = WkSht.Cells(r, 2)
        If Macth1 = "" Then
            Exit For
        Else
            myOtherSheet.Cells(j, 2).Value = Match1
            j = j + 1
        ' Missing End If
    Next Match1
End If
于 2013-07-12T10:26:25.993 回答