'Exit For' can only appear inside a 'For' statement

An Exit For statement occurs outside a For loop. Exit For is valid only between a For or For Each statement and a corresponding Next statement.

Error ID: BC30096

To correct this error

  1. Make sure a valid For or For Each statement precedes the Exit For, and a valid Next statement appears after it.

  2. Verify that other control structures within the For loop are correctly terminated.

See Also

Reference

For...Next Statement (Visual Basic)

For Each...Next Statement (Visual Basic)