Celeb Glow
news | March 03, 2026

Compile error: Next without For

Searched but I think my code is correct now, but still get this dreaded compile error, but I cannot determine why! Code is as follows:

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

1 Answer

Fix the Else positions:

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy