How do I Fix "Compile error: For without Next" in VBA

Viewed 53

So I have a fairly large dataset where some values are in the wrong place. I found this script to search up cells in column C containing "0". I would like to mark the cell and the cell to the right of it and move them one cell to the right, but I keep getting the "Compile error: For without Next".

Sub Clean()
    Dim row As Long

    For row = 2 To LastRow
        If Range("C" & row).Value Like "0" Then
            Dim i As Integer
            For i = 1 To 2
                Range("C" & row).Insert Shift:=xlToRight
            Next
        End If
End Sub

Any help is greatly appreciated

1 Answers

seems it is a typo, you need to put an additional "next" after "End If" statement.

Sub Clean()
    Dim row As Long

    For row = 2 To LastRow
        If Range("C" & row).Value Like "0" Then
            Dim i As Integer
            For i = 1 To 2
                Range("C" & row).Insert Shift:=xlToRight
            Next
        End If
    Next
End Sub
Related