Comment sortir prématurément d’une boucle While…Wend en VBA ?
Il n’y a pas d’instruction Exit While en VBA. Solutions :
- Utilisez une variable booléenne :
Dim sortir As Boolean
While condition And Not sortir
If autreCond Then sortir = True
Wend
- 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.