jeudi 22 août 2019

Code throws "End if without block If" when attempting to compile. (If statement used for nested loop)

Attempting to prompt excel to move into another nested loop should one of my variables become greater then a given value. However, when attempting to compile, I receive the "End If without block If" error.

I've attempted to place a "Endif" after the "next m", but with no success. I've tried a few other workarounds that don't use "if"; however, a if-statement seems inevitable with the code I am trying to write.

For i = 1 To 4000000

r = x + y
Worksheets("sheet1").Cells(Z, 1).Value = r
Z = Z + 1


x = r + y
Worksheets("sheet1").Cells(Z, 1).Value = x
Z = Z + 1


y = r + x
Worksheets("Sheet1").Cells(Z, 1).Value = y
Z = Z + 1

If Z > 499 Then For m = 1 To 501

    e = 1

    d = Worksheets("sheet1").Cells(e, 1).Value Mod 2
    If d = 1 Then Worksheets("sheet1").Cells(e, 1).ClearContents

    e = e + 1

    If e > 500 Then Range(q, 1) = "=Sum(A1:A500)" And Z = 1 And q = q + 1

Next m
End If
Next i

Aucun commentaire:

Enregistrer un commentaire