Excuter une macro avec un commandButton

Bonsoir à tout le Forum,

Je viens vers vous, un petit souci, je débute et je plante sur un code.

J'explique, Un commandButton"Validez". J'aimerai que lorsque je valide il m’exécute une macro. Si A4 = lundi il m’exécute la macro lundi,....

Voilà le code :

Private Sub Validez_Click()

Range("A4") = Secteurs

Range("B21") = Jours

Unload Options

If ("A4") = "Lundi" Then Application.Run ("Lun")

If ("A4") = "Mardi" Then Application.Run ("Mar")

If ("A4") = "Mercredi" Then Application.Run ("Mer")

If ("A4") = "Jeudi" Then Application.Run ("Jeu")

If ("A4") = "Vendredi" Then Application.Run ("Ven")

Voilà le code de la macro:

Sub Lun()

'

' Lundi Macro

Application.Goto Reference:="Lundi"

Range("A6").Select

End Sub

End Sub

Merci d'avance Coco

Bonsoir

Modifies chaque lignes où tu as If ("A4") = par (exemple)

If Range("A4") = "Lundi" Then Application.Run ("Lun")

Si pas ça

Bonsoir Banzai;

Cela ne fonctionne pas.

Je vous joins un fichier,

Merci

Bonsoir

Essayes cette méthode

Remplaces la macro correspondante par celle-ci

Private Sub Validez_Click()

    Range("A4") = Secteurs
    Range("B21") = Jours

    Select Case Me.Jours
      Case "Lundi": Application.Run ("Lun")
      Case "Mardi": Application.Run ("Mar")
      Case "Mercredi": Application.Run ("Mer")
      Case "Jeudi": Application.Run ("Jeu")
      Case "Vendredi": Application.Run ("Ven")
      Case Else
        MsgBox "Non prévu"
    End Select

    Unload Me
End Sub

Bonjour Banzai,

Ça fonctionne à merveille, Merci pour le temps passé.

Coco

Rechercher des sujets similaires à "excuter macro commandbutton"