IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

méthode d’allègement d'un code.


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Juillet 2012
    Messages
    201
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2012
    Messages : 201
    Par défaut méthode d’allègement d'un code.
    Bonsoir,
    je souhaiterai recourir à une technique pour alléger mon code que voici:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
     
    Private Sub CommandButton1_Click()
     
    If ComboBox1.Text = "BRH" And ComboBox2.Text = "Béton dense" And ComboBox4.Text = "Mur" And ComboBox5.Text = "Refend" Then
     
             ThisWorkbook.Worksheets("Feuil3").Range("I28").Value = (ComboBox6.Value) * 0.01 * ThisWorkbook.Worksheets("Feuil2").Range("B2").Value
             ThisWorkbook.Worksheets("Feuil3").Range("K28").Value = (ThisWorkbook.Worksheets("Feuil3").Range("I28").Value) / (ThisWorkbook.Worksheets("Feuil2").Range("B2").Value)
     
     
             ThisWorkbook.Worksheets("Feuil3").Range("J28").Value = (ComboBox3.Value) * 0.01 * ThisWorkbook.Worksheets("Feuil2").Range("B2").Value
             ThisWorkbook.Worksheets("Feuil3").Range("L28").Value = (ThisWorkbook.Worksheets("Feuil3").Range("J28").Value) / (ThisWorkbook.Worksheets("Feuil2").Range("B2").Value)
             ThisWorkbook.Worksheets("Feuil3").Range("N28").Value = ThisWorkbook.Worksheets("Feuil2").Range("C2").Value
             ThisWorkbook.Worksheets("Feuil3").Range("H28").Value = ThisWorkbook.Worksheets("Feuil2").Range("D2").Value
             rayonnement
             rayonnementM
             NiveauP
     
       ElseIf ComboBox1.Text = "BRH" And ComboBox2.Text = "Brique pleine" And ComboBox4.Text = "Mur" Then
     
            ThisWorkbook.Worksheets("Feuil3").Range("J28").Value = (ComboBox3.Value) * 0.01 * ThisWorkbook.Worksheets("Feuil2").Range("B6").Value
            ThisWorkbook.Worksheets("Feuil3").Range("L28").Value = (ThisWorkbook.Worksheets("Feuil3").Range("J28").Value) / (ThisWorkbook.Worksheets("Feuil2").Range("B2").Value)
            ThisWorkbook.Worksheets("Feuil3").Range("N28").Value = ThisWorkbook.Worksheets("Feuil2").Range("C6").Value
            ThisWorkbook.Worksheets("Feuil3").Range("H28").Value = ThisWorkbook.Worksheets("Feuil2").Range("D6").Value
            rayonnement
            rayonnementM
            NiveauP
     
       ElseIf ComboBox1.Text = "BRH" And ComboBox2.Text = "Brique creuse" And ComboBox4.Text = "Mur" Then
     
            ThisWorkbook.Worksheets("Feuil3").Range("J28").Value = (ComboBox3.Value) * 0.01 * ThisWorkbook.Worksheets("Feuil2").Range("B7").Value
            ThisWorkbook.Worksheets("Feuil3").Range("L28").Value = (ThisWorkbook.Worksheets("Feuil3").Range("J28").Value) / (ThisWorkbook.Worksheets("Feuil2").Range("B2").Value)
            ThisWorkbook.Worksheets("Feuil3").Range("N28").Value = ThisWorkbook.Worksheets("Feuil2").Range("C7").Value
            ThisWorkbook.Worksheets("Feuil3").Range("H28").Value = ThisWorkbook.Worksheets("Feuil2").Range("D7").Value
            rayonnement
            rayonnementM
            NiveauP
     
       ElseIf ComboBox1.Text = "BRH" And ComboBox2.Text = "Pan de bois" And ComboBox4.Text = "Mur" Then
     
            ThisWorkbook.Worksheets("Feuil3").Range("J28").Value = (ComboBox3.Value) * 0.01 * ThisWorkbook.Worksheets("Feuil2").Range("B8").Value
            ThisWorkbook.Worksheets("Feuil3").Range("L28").Value = (ThisWorkbook.Worksheets("Feuil3").Range("J28").Value) / (ThisWorkbook.Worksheets("Feuil2").Range("B2").Value)
            ThisWorkbook.Worksheets("Feuil3").Range("N28").Value = ThisWorkbook.Worksheets("Feuil2").Range("C8").Value
            ThisWorkbook.Worksheets("Feuil3").Range("H28").Value = ThisWorkbook.Worksheets("Feuil2").Range("D8").Value
            rayonnement
            rayonnementM
            NiveauP
     
       ElseIf ComboBox1.Text = "BRH" And ComboBox2.Text = "Pan de fer" And ComboBox4.Text = "Mur" Then
     
            ThisWorkbook.Worksheets("Feuil3").Range("J28").Value = (ComboBox3.Value) * 0.01 * ThisWorkbook.Worksheets("Feuil2").Range("B9").Value
            ThisWorkbook.Worksheets("Feuil3").Range("L28").Value = (ThisWorkbook.Worksheets("Feuil3").Range("J28").Value) / (ThisWorkbook.Worksheets("Feuil2").Range("B2").Value)
            ThisWorkbook.Worksheets("Feuil3").Range("N28").Value = ThisWorkbook.Worksheets("Feuil2").Range("C9").Value
            ThisWorkbook.Worksheets("Feuil3").Range("H28").Value = ThisWorkbook.Worksheets("Feuil2").Range("D9").Value
            rayonnement
            rayonnementM
            NiveauP
       End If
     
     
     
     
    End Sub
    rayonnement , rayonnementM et NiveauP sont des procédures dans le module1 que je fais appelle ici dans le module de l'userform. La feuille 2 contient les valeurs que je fais chercher pour mes calculs et j'envoi le résultat dans la feuille3 à titre facultatif pour avoir juste une idée de la cohérence de sa valeur . Voilà est il possible d'utiliser une autre méthode pour faire appel à ces valeurs et continuer le module de l'userform en l’allégeant ( d'autant plus que j'aurais d'autres conditions et ça risque d'être à nouveau lourd)? Merci

  2. #2
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Une alternative (non testée)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Private Sub CommandButton1_Click()
    Dim U As Double, V As Double, W As Double
    Dim Flag As Boolean
    Dim X As Variant
    Dim n As Byte
     
    If ComboBox1.Text = "BRH" And ComboBox4.Text = "Mur" Then
        If ComboBox2.Text = "Béton dense" And ComboBox5.Text = "Refend" Then
            V = 0.01 * ComboBox6.Value
            n = 2
        ElseIf ComboBox2.Text = "Brique pleine" Then
            n = 6
        ElseIf ComboBox2.Text = "Brique creuse" Then
            n = 7
        ElseIf ComboBox2.Text = "Pan de bois" Then
            n = 8
        ElseIf ComboBox2.Text = "Pan de fer" Then
            n = 9
        Else
            Flag = True
        End If
    Else
        Flag = True
    End If
     
    If Not Flag Then
        With ThisWorkbook.Worksheets("Feuil2")
            U = .Range("B2").Value
            X = .Range("B" & n & ":D" & n).Value
        End With
        W = 0.01 * ComboBox3
     
        With ThisWorkbook.Worksheets("Feuil3")
            If V > 0 Then
                .Range("I28").Value = V * X(1, 1)
                .Range("K28").Value = V
            End If
            .Range("J28").Value = W * X(1, 1)
            If U <> 0 Then .Range("L28").Value = W * X(1, 1) / U
            .Range("N28").Value = X(1, 2)
            .Range("H28").Value = X(1, 3)
        End With
     
        rayonnement
        rayonnementM
        NiveauP
    End If
    End Sub

  3. #3
    Membre chevronné Avatar de Bear the french
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    352
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Saône et Loire (Bourgogne)

    Informations forums :
    Inscription : Mai 2012
    Messages : 352
    Par défaut
    Bonjour,

    Mon essai à tester :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Private Sub CommandButton1_Click()
    Dim x As Integer
    x = 0
    If ComboBox1.Text = "BRH" And ComboBox4.Text = "Mur" Then
        Select Case ComboBox2.Text
            Case "Béton dense": x = 2
            Case "Brique pleine": x = 6
            Case "Brique creuse": x = 7
            Case "Pan de bois": x = 8
            Case "Pan de fer": x = 9
        End Select
    End If
    If x <> 0 Then
        With ThisWorkbook.Worksheets("Feuil3")
            If x = 2 And ComboBox5.Text = "Refend" Then
                 .Range("I28").Value = (ComboBox6.Value) * 0.01 * ThisWorkbook.Worksheets("Feuil2").Range("B" & x).Value
                 .Range("K28").Value = (.Range("I28").Value) / (ThisWorkbook.Worksheets("Feuil2").Range("B" & x).Value)
            End If
            .Range("J28").Value = (ComboBox3.Value) * 0.01 * ThisWorkbook.Worksheets("Feuil2").Range("B" & x).Value
            .Range("L28").Value = (.Range("J28").Value) / (ThisWorkbook.Worksheets("Feuil2").Range("B2").Value)
            .Range("N28").Value = ThisWorkbook.Worksheets("Feuil2").Range("C" & x).Value
            .Range("H28").Value = ThisWorkbook.Worksheets("Feuil2").Range("D" & x).Value
            rayonnement
            rayonnementM
            NiveauP
        End With
    End If
    End Sub
    Bertrand

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Audit] Quelle méthode pour auditer un code source ?
    Par EvilAngel dans le forum Qualité
    Réponses: 11
    Dernier message: 16/05/2011, 12h52
  2. [JNI] appel d'une méthode java depuis le code natif
    Par myryad dans le forum Entrée/Sortie
    Réponses: 3
    Dernier message: 19/05/2009, 11h23
  3. Appel d'une méthode C++ depuis un code C
    Par fantomchris dans le forum MFC
    Réponses: 3
    Dernier message: 02/05/2008, 12h52
  4. [Etat-Transition] [XMI] Méthode de génération de code
    Par koneko dans le forum Autres Diagrammes
    Réponses: 2
    Dernier message: 14/03/2007, 18h26
  5. Comparatif entre 2 méthodes d'écriture de code PHP
    Par Chengj dans le forum Langage
    Réponses: 2
    Dernier message: 24/11/2005, 21h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo