Sortir d'une boucle While...Wend

Comment sortir prématurément d’une boucle While…Wend en VBA ?

Il n’y a pas d’instruction Exit While en VBA. Solutions :

  1. Utilisez une variable booléenne :
Dim sortir As Boolean
While condition And Not sortir
    If autreCond Then sortir = True
Wend

  1. Convertissez en Do While (recommandé) :
Do While condition
    If autreCond Then Exit Do
Loop

La boucle Do While...Loop est préférable car elle supporte Exit Do.