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 :

Comment activer plusieurs sub par un bouton


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Octobre 2011
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

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

    Informations forums :
    Inscription : Octobre 2011
    Messages : 26
    Par défaut Comment activer plusieurs sub par un bouton
    Bonjour, Est-ce que quelqu'un pourrait me dire comment on peut activer plusieurs sub une à la suite de l'autre par un simple click sur un bouton. Je m'explique, j'essais de faire un programme qui suite à une série de choix fait dans différentes listes déroulantes qui sont dans différentes cellulles, l'utilisateur, en appuyant sur le bouton active les sub associées aux différentes cellulles.

  2. #2
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Par défaut
    bonjour ..

    "Active" ? ... exécute ?


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    sub CommandButton1_Click
     
       MaSub1 'Exécute "MaSub1"
       MaSub2 'Exécute "MaSub2"
       MaSub3 'Exécute "MaSub3"
     
    End sub

  3. #3
    Membre averti
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Octobre 2011
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

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

    Informations forums :
    Inscription : Octobre 2011
    Messages : 26
    Par défaut
    Le problème est que la première sub s'exécute, mais elle arrête à la fin et la deuxième ne s'exécute pas. À noter que les sub sont enregistrées par l'enregistreur de macro

    ******************************************

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Private Sub CommandButton1_Click()
     
    NET4 'execute "NET4"
    carte_principale 'execute "carte_principale"
    End Sub
    1ière sub

    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
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    Sub NET4()
    '
    ' NET4 Macro
     
    If Range("B6") = "NET-4" Then
        Sheets("Cabinet").Select
     
    Range("P8:P11").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Selection.Merge
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 90
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = True
        End With
        ActiveCell.FormulaR1C1 = "NET-4"
        With ActiveCell.Characters(Start:=1, Length:=5).Font
            .Name = "Arial"
            .FontStyle = "Regular"
            .Size = 9
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("C8").Select
     
    Else
     
    If Range("B6") = "Na" Then
        Sheets("Cabinet").Select
        Range("P8:P11").Select
        Selection.ClearContents
        With Selection
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = True
        End With
        Selection.UnMerge
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
     
        Range("a1").Select
        End If
        End If
     
    End Sub
    2e sub

    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
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    Sub NET4()
    '
    ' NET4 Macro
     
    If Range("B6") = "NET-4" Then
        Sheets("Cabinet").Select
     
    Range("P8:P11").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Selection.Merge
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 90
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = True
        End With
        ActiveCell.FormulaR1C1 = "NET-4"
        With ActiveCell.Characters(Start:=1, Length:=5).Font
            .Name = "Arial"
            .FontStyle = "Regular"
            .Size = 9
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("C8").Select
     
    Else
     
    If Range("B6") = "Na" Then
        Sheets("Cabinet").Select
        Range("P8:P11").Select
        Selection.ClearContents
        With Selection
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = True
        End With
        Selection.UnMerge
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
     
        Range("a1").Select
        End If
        End If
     
    End Sub

  4. #4
    Membre averti Avatar de ssoltani
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2011
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2011
    Messages : 28
    Par défaut
    Les Sub sont ils sur la même feuille de calcul ?

    Par contre, tu as copié deux fois le même sub.

  5. #5
    Membre averti
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Octobre 2011
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

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

    Informations forums :
    Inscription : Octobre 2011
    Messages : 26
    Par défaut
    Bonjour,

    Les sub sont sur la même feuille de calcul, mais elles agissent sur 2 feuilles différentes. Autrement dit, les listes déroulantes sont sur la feuille 1, mais les sub agissent sur la feuille 2. Et oui en effet j'ai malheureusement copié 2 fois la même sub. La 2e sub est identique mais tracera les lignes différemment. Comme je l'ai dit, il n'y a que la première sub qui 'exécute suite a l'activation du bouton.

    Merci de ton aide

  6. #6
    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
    Déjà évite les Select, tu auras moins de désagréments
    au lieu de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Sheets(X).select
    Range(Y).select
    Selection.interior.colorindex=3
    fais comme ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Sheets(X).Range(Y).interior.colorindex=3
    Tu auras le résultat voulu en restant sur place.

Discussions similaires

  1. Comment avoir plusieurs like par page : un par article
    Par aimar022 dans le forum Facebook
    Réponses: 0
    Dernier message: 04/10/2011, 19h18
  2. Réponses: 1
    Dernier message: 14/04/2011, 11h40
  3. [XL-2007] Possibilité de faire activer des macros par un bouton ?
    Par Scatmax dans le forum Excel
    Réponses: 2
    Dernier message: 19/05/2010, 08h27
  4. Comment créer plusieurs TEdit par programmation?
    Par rebelor dans le forum Delphi
    Réponses: 2
    Dernier message: 02/06/2007, 17h30
  5. Comment remplacer le clavier par des boutons ?
    Par aliwassem dans le forum Langage
    Réponses: 1
    Dernier message: 14/12/2005, 19h00

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