macro bouton active x

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

mimi1958

XLDnaute Junior
bonjour a tous

Je voudrai savoir si il est possible d'affecter une macro a un bouton active x ?
sur ma feuille 1 exel j'ai bouton 1 , bouton 2, bouton 3 , bouton 4
quand je clic sur bouton 1 il devient bleu , quand je clic sur bouton 2 il devient bleu et le bouton 1 passe au vert ainsi de suite.
maintenant sur le bouton 1 ( feuille 1 ) , je vourdrai rajouter en plus de la couleur , lui attribuer une macro pour aller sur la feuille 2
est ce possible ?
voici les codes que j'ai utilise :

Private Sub CommandButton1_Click()
Range("A1") = "Oui"
CommandButton1.BackColor = RGB(0, 0, 240)
CommandButton2.BackColor = RGB(0, 240, 0)

End Sub

Private Sub CommandButton2_Click()
Range("A1") = "Non"
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton2.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton3_Click()
Range("A1") = "Non"
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton4_Click()
Range("A1") = "Non"
CommandButton3.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton5_Click()
Range("A1") = "Non"
CommandButton4.BackColor = RGB(0, 240, 0)
CommandButton5.BackColor = RGB(0, 0, 240)
CommandButton5.BackColor = RGB(0, 240, 0)
End Sub

Merci pour votre collaboration .( je vous joint lefichier
 

Pièces jointes

Bonjour
tu rajoutes simplement dans la partie de la macro du bouton 1
Sheets("nom de la feuille").activate

Code:
Private Sub CommandButton1_Click()
TOUR1
Range("A1") = "Oui"
CommandButton1.BackColor = RGB(0, 0, 240)
CommandButton2.BackColor = RGB(0, 240, 0)
Sheets("sheet2").Activate
 
impec ca marche merci
encore une question
quand je suis sur le dernier bouton et que je clique dessus , il devient bleu
mais quand je reclick sur le bouton 1 comment faire pour que le bouton 4 deviennet vert
une sorte de boubcle en fait
je n'y suis pas arrive
merci par avance

codes :
Private Sub CommandButton1_Click()
Range("A1") = "Oui"
CommandButton1.BackColor = RGB(0, 0, 240)
CommandButton2.BackColor = RGB(0, 240, 0)
Sheets("sheet2").Activate
End Sub

Private Sub CommandButton2_Click()
Range("A1") = "Non"
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton2.BackColor = RGB(0, 0, 240)
Sheets("sheet3").Activate
End Sub

Private Sub CommandButton3_Click()
Range("A1") = "Non"
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton4_Click()
Range("A1") = "Non"
CommandButton3.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton5_Click()
Range("A1") = "Non"
CommandButton4.BackColor = RGB(0, 240, 0)
CommandButton5.BackColor = RGB(0, 0, 240)
End Sub
 
Re,

Comme ceci
Code:
Private Sub CommandButton1_Click()
TOUR1
Range("A1") = "Oui"
CommandButton1.BackColor = RGB(0, 0, 240)
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 240, 0)
Sheets("sheet2").Activate
End Sub

Private Sub CommandButton2_Click()
Range("A1") = "Non"
CommandButton2.BackColor = RGB(0, 0, 240)
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 240, 0)

End Sub

Private Sub CommandButton3_Click()
Range("A1") = "Non"
CommandButton3.BackColor = RGB(0, 0, 240)
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 240, 0)

End Sub

Private Sub CommandButton4_Click()
Range("A1") = "Non"
CommandButton4.BackColor = RGB(0, 0, 240)
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 240, 0)

End Sub

Private Sub CommandButton5_Click()
Range("A1") = "Non"
CommandButton4.BackColor = RGB(0, 240, 0)
CommandButton5.BackColor = RGB(0, 0, 240)
CommandButton5.BackColor = RGB(0, 240, 0)
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
474
  • Question Question
Microsoft 365 Probléme VBA
Réponses
8
Affichages
333
Réponses
10
Affichages
303
Réponses
4
Affichages
217
Retour