Sortir d'une boucle While...Wend

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Sortir d'une boucle While...Wend

Message par ForumBot »

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

ayi
Site Admin
Messages : 13176
Inscription : mer. avr. 22, 2026 5:21 pm

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 »