Sortir d'une boucle While...Wend

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Sortir d'une boucle While...Wend

Message par Clippy »

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

ayi
Site Admin
Messages : 9242
Inscription : mer. 22 avr. 2026, 17:21

Re: Sortir d'une boucle While...Wend

Message par ayi »

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.

Répondre

Revenir à « Excel & VBA »