Share via

LOOP WITHOUT DO ERROR

kevin lazell 0 Reputation points
2026-04-09T09:23:59.68+00:00

X = 1

Do

X = X + 1

If Range("n" & X) = 1 Or Range("o" & X) > 0 Then

Range("d3") = Range("s" & X)

Range("f1") = Range("t" & X) / 10

Range("d4") = Range("t" & X)

Range("f2") = Range("u" & X)

Range("f3") = Range("v" & X) / 10

Range("g4") = Range("w" & X)

If Range("o" & X) < 5 Then Range("d3") = Range("d3") + Range("o" & X)

If Range("o" & X) > 4 Then Range("g4") = Range("g4") + Range("o" & X)

If X = 100 Then GoTo LEAP:

Loop

LEAP:

THIS CODE GIVES ME A LOOP WITHOUT DO ERROR WHAT IS WRONG

Microsoft 365 and Office | Excel | For home | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. Emmanuel Santana 38,175 Reputation points Independent Advisor
    2026-04-09T10:03:34.75+00:00

    Hello. The GoTo statement is interfering with how VBA parses the loop, which triggers the “Loop without Do” error.

    Remove the GoTo and exit the loop properly using Exit Do:

    X = 1
    
    Do
        X = X + 1
    
        If Range("n" & X) = 1 Or Range("o" & X) > 0 Then
            Range("d3") = Range("s" & X)
            Range("f1") = Range("t" & X) / 10
            Range("d4") = Range("t" & X)
            Range("f2") = Range("u" & X)
            Range("f3") = Range("v" & X) / 10
            Range("g4") = Range("w" & X)
    
            If Range("o" & X) < 5 Then Range("d3") = Range("d3") + Range("o" & X)
            If Range("o" & X) > 4 Then Range("g4") = Range("g4") + Range("o" & X)
        End If
    
        If X = 100 Then Exit Do
    
    Loop
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.