Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 18/10/2011, 01h19   #1
Invité de passage
 
Inscription : mars 2010
Messages : 39
Détails du profil
Informations forums :
Inscription : mars 2010
Messages : 39
Points : 3
Points : 3
Par défaut Stopper une procédure dans le code

Bonjour,

J'ai une procédure qui fait des itérations. Je voudrais la stopper dès qu'une certaine valeur est inférieur à un coefficient, car dans ce cas-là l'itération ne sert à rien.

Comment puis-je intégrer le fait d'arrêter la procédure ? J'ai essayer Stop, Exit Sub, sans succès...

Merci de votre réponse.
Sylv3D est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/10/2011, 01h41   #2
Expert Confirmé
 
Homme Philippe
ex Observeur CGG / Analyste prog.
Inscription : juin 2006
Messages : 1 706
Détails du profil
Informations personnelles :
Nom : Homme Philippe
Localisation : France, Finistère (Bretagne)

Informations professionnelles :
Activité : ex Observeur CGG / Analyste prog.

Informations forums :
Inscription : juin 2006
Messages : 1 706
Points : 3 627
Points : 3 627
Salut, sans doute dans http://silkyroad.developpez.com/vba/boucles/ ou http://silkyroad.developpez.com/VBA/GestionErreurs/
__________________
Pensez à Voter, d'avance merci. ( Pouces en bas à la droite de Citer )
Balisez votre code après l'avoir indenté sous Excel via Smart Indenter
Autre utilitaire : MZ Tools 3.0 VBA

Contribution : Excel / Word / PDF avec Adobe Acrobat Pro / PDFCreator 1 2
kiki29 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/10/2011, 05h26   #3
Invité de passage
 
Inscription : mars 2010
Messages : 39
Détails du profil
Informations forums :
Inscription : mars 2010
Messages : 39
Points : 3
Points : 3
Merci pour tes liens.
J'utilise une boucle en Do While + Loop, et à priori un Exit Do me permettrait d'arrêter la boucle... mais sans résultat.
Je mets ici mon code (je vous épargne toutes les définitions des fonctions), peut-être que mon erreur va vous apparaître flagrante.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Sub NRmethod(N, eps, maxval)
 
    Dim iter As Integer
 
    Tw0 = Cells(23, 5)
    Tg0 = Cells(23, 4)
    Tf0 = Cells(23, 6)
    qs0 = Cells(23, 2)
    i = 24
 
    Do While N > 0
        Application.StatusBar = "N= " & N    
 
            If Abs(determinant(qs0, Tw0, Tg0, Tf0)) < eps Then
            MsgBox "Error"
            Exit Do
            End If
 
        Tw = Tw0 - jacobianinvmat(0, 0) * fw(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(0, 1) * fg(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(0, 2) * ff(Tw0, Tg0, Tf0)
        Tg = Tg0 - jacobianinvmat(1, 0) * fw(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(1, 1) * fg(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(1, 2) * ff(Tw0, Tg0, Tf0)
        Tf = Tf0 - jacobianinvmat(2, 0) * fw(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(2, 1) * fg(qs0, Tw0, Tg0, Tf0) - jacobianinvmat(2, 2) * ff(Tw0, Tg0, Tf0)
 
        Cells(i, 5) = Tw
        Cells(i, 4) = Tg
        Cells(i, 6) = Tf
 
            If Abs(fw(qs, Tw, Tg, Tf)) < eps And Abs(fg(qs, Tw, Tg, Tf)) < eps And Abs(ff(Tw, Tg, Tf)) < eps Then
            iter = 100 - N
            Cells(i + 1, 6) = Tw
            Cells(i + 1, 7) = Tg
            Cells(i + 1, 8) = Tf
            MsgBox "Convergence after " & iter & " iterations"
            Exit Do
            End If
 
            If Abs(fw(qs, Tw, Tg, Tf)) > maxval And Abs(fg(qs, Tw, Tg, Tf)) > maxval And Abs(ff(Tw, Tg, Tf)) > maxval Then
            iter = 100 - N
            MsgBox "Divergence after " & iter & " iterations"
            Exit Do
            End If
 
        N = N - 1
        i = i + 1
        Tw0 = Tw
        Tg0 = Tg
        Tf0 = Tf
    Loop
 
    MsgBox "No convergence after " & N & " iterations"
 
End Sub
Sylv3D est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/10/2011, 08h45   #4
Nouveau Membre du Club
 
Femme Alias Toty
Chargé d'affaire
Inscription : octobre 2011
Messages : 10
Détails du profil
Informations personnelles :
Nom : Femme Alias Toty
Âge : 27
Localisation : France, Loire Atlantique (Pays de la Loire)

Informations professionnelles :
Activité : Chargé d'affaire
Secteur : Industrie

Informations forums :
Inscription : octobre 2011
Messages : 10
Points : 34
Points : 34
Bonjour au forum

une Proposition avec une étiquette

Goto Sortie

avec Sortie: la ou on veux aller


Toty
toty44 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/10/2011, 10h11   #5
Membre Expert
 
Homme
Retraité
Inscription : avril 2011
Messages : 692
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Retraité

Informations forums :
Inscription : avril 2011
Messages : 692
Points : 1 443
Points : 1 443
Bonjour,

Ton code semble correct.

Seule anomalie : quand tu sors de la boucle via un exit do, tu affiches quand même le message "No convergence after " & N & " iterations"

Cordialement.
gFZT82 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h18.


 
 
 
 
Partenaires

Hébergement Web