For..Next error 'End if without block if'

M

Mike R.

Hi - I am a little stuck here. I am sure it is something easy.

Sub testing()

Dim irows As Integer
Dim iloop
Dim iloop2
irows = ActiveSheet.UsedRange.Rows.Count

For iloop = irows To 2 Step -1
If Cells(iloop, 8) <> "" Then _
For iloop2 = irows To 2 Step -1
If Cells(iloop2, 11) = Cells(iloop, 8) Then _
Cells(iloop2, 5).Value = Cells(iloop, 5).Value
Cells(iloop, 1).EntireRow.Delete
Next iloop2
Next iloop
End Sub


I am getting the 'End if without Block if' error. Help please.

Thank you,
 
C

carlo

Hi - I am a little stuck here.  I am sure it is something easy.  

Sub testing()

    Dim irows As Integer
    Dim iloop
    Dim iloop2
    irows = ActiveSheet.UsedRange.Rows.Count

    For iloop = irows To 2 Step -1
        If Cells(iloop, 8) <> "" Then _
            For iloop2 = irows To 2 Step -1
                If Cells(iloop2, 11) = Cells(iloop, 8) Then _
                    Cells(iloop2, 5).Value = Cells(iloop, 5).Value
                    Cells(iloop, 1).EntireRow.Delete
            Next iloop2
    Next iloop
End Sub

I am getting the 'End if without Block if' error.  Help please.  

Thank you,

you forget the end if between next iloop2 and next iloop

cheers carlo
 
C

carlo

Hi - I am a little stuck here.  I am sure it is something easy.  

Sub testing()

    Dim irows As Integer
    Dim iloop
    Dim iloop2
    irows = ActiveSheet.UsedRange.Rows.Count

    For iloop = irows To 2 Step -1
        If Cells(iloop, 8) <> "" Then _
            For iloop2 = irows To 2 Step -1
                If Cells(iloop2, 11) = Cells(iloop, 8) Then _
                    Cells(iloop2, 5).Value = Cells(iloop, 5).Value
                    Cells(iloop, 1).EntireRow.Delete
            Next iloop2
    Next iloop
End Sub

I am getting the 'End if without Block if' error.  Help please.  

Thank you,

And also before next iloop2

in VBA If needs to be ended with end if as long as it is one more then
one line.

cheers
Carlo
 
M

Mike R.

Thank you Carlo. Can't believe I missed that. I have updated it, but am
still getting the same error. Here is my new code:
Sub testing()

Dim irows As Integer
Dim iloop
Dim iloop2
irows = ActiveSheet.UsedRange.Rows.Count

For iloop = irows To 2 Step -1
If Cells(iloop, 8) <> "" Then _
For iloop2 = irows To 2 Step -1
If Cells(iloop2, 11) = Cells(iloop, 8) Then _
Cells(iloop2, 5).Value = Cells(iloop, 5).Value
Cells(iloop, 1).EntireRow.Delete
End If
Next iloop2
End If
Next iloop
End Sub

Does it look right?
Thanks,
Mike
 
C

carlo

Thank you Carlo.  Can't believe I missed that.  I have updated it, butam
still getting the same error.  Here is my new code:
Sub testing()

    Dim irows As Integer
    Dim iloop
    Dim iloop2
    irows = ActiveSheet.UsedRange.Rows.Count

    For iloop = irows To 2 Step -1
        If Cells(iloop, 8) <> "" Then _
            For iloop2 = irows To 2 Step -1
                If Cells(iloop2, 11) = Cells(iloop, 8) Then _
                    Cells(iloop2, 5).Value = Cells(iloop, 5).Value
                    Cells(iloop, 1).EntireRow.Delete
                 End If
            Next iloop2
        End If
    Next iloop
End Sub

Does it look right?
Thanks,
Mike








- Show quoted text -

Hei Mike

the _ mess your code up, this should work:

Sub testing()

Dim irows As Integer
Dim iloop
Dim iloop2
irows = ActiveSheet.UsedRange.Rows.Count


For iloop = irows To 2 Step -1
If Cells(iloop, 8) <> "" Then
For iloop2 = irows To 2 Step -1
If Cells(iloop2, 11) = Cells(iloop, 8) Then
Cells(iloop2, 5).Value = Cells(iloop, 5).Value
Cells(iloop, 1).EntireRow.Delete
End If
Next iloop2
End If
Next iloop
End Sub


cheers

Carlo
 
B

Bdra

Try removing the underscores after Then. In VBA underscores signify that the
line continues, but the If ... Then ... End If structure requires Then to be
the last term on the first line.

Best,
Bo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top