编译错误:Next 没有 For

编译错误:Next 没有 For

经过搜索,我认为我的代码现在是正确的,但仍然会出现这个可怕的编译错误,但我无法确定原因!代码如下:

Dim LastRow As Long
Dim i As Integer

LastRow = Cells(1, "A").End(xlDown).Row

For i = 2 To LastRow

If Cells(i, 19).Offset(0, -6).Value = "4125551212" Then
    Cells(i, 19).Value = ""

    Else
        If Cells(i, 19).Offset(0, -6).Value = Cells(i, 19).Offset(1, -6).Value And Cells(i, 19).Offset(1, -6).Value = Cells(i, 19).Offset(0, -6).Value Then
        Cells(i, 19).Value = "Y"

    Else
        If Cells(i, 19).Offset(0, -6).Value = Cells(i, 19).Offset(1, -6).Value Then
        Cells(i, 19).Value = "Y"

    Else
        If Cells(i, 19).Offset(0, -6).Value = Cells(i, 19).Offset(-1, -6).Value And Cells(i, 19).Offset(-1, 0).Value = "Y" Then
        Cells(i, 19).Value = "Y"

    Else
        Cells(i, 19).Value = ""

End If

Next i

答案1

修复Else位置:

Sub jhgf()

    Dim LastRow As Long
    Dim i As Integer

    LastRow = Cells(1, "A").End(xlDown).Row

    For i = 2 To LastRow

        If Cells(i, 19).Offset(0, -6).Value = "4125551212" Then
            Cells(i, 19).Value = ""

            ElseIf Cells(i, 19).Offset(0, -6).Value = Cells(i, 19).Offset(1, -6).Value And Cells(i, 19).Offset(1, -6).Value = Cells(i, 19).Offset(0, -6).Value Then
                Cells(i, 19).Value = "Y"

            ElseIf Cells(i, 19).Offset(0, -6).Value = Cells(i, 19).Offset(1, -6).Value Then
                Cells(i, 19).Value = "Y"

            ElseIf Cells(i, 19).Offset(0, -6).Value = Cells(i, 19).Offset(-1, -6).Value And Cells(i, 19).Offset(-1, 0).Value = "Y" Then
                Cells(i, 19).Value = "Y"

            Else
                Cells(i, 19).Value = ""

        End If

    Next i
End Sub

相关内容