XL 2019 Simplifier un code VBA

Yann71

XLDnaute Occasionnel
Bonjour le Forum,

J'ai un code qui dois se répéter plus de 20 x et j'aurais aimer savoir si li y a avait le moyen de la condencé
toutes ces lignes. Cela concerne des ToggeBoutton qui permettes d'afficher la note d'une cellule.

VB:
Private Sub ToggleButton1_Click()
    If [C2].Comment.Visible Then [C2].Comment.Visible = False Else [C2].Comment.Visible = True
End Sub

Private Sub ToggleButton10_Click()
 If [C11].Comment.Visible Then [C11].Comment.Visible = False Else [C11].Comment.Visible = True
End Sub

Private Sub ToggleButton11_Click()
 If [C12].Comment.Visible Then [C12].Comment.Visible = False Else [C12].Comment.Visible = True
End Sub

Private Sub ToggleButton12_Click()
 If [C13].Comment.Visible Then [C13].Comment.Visible = False Else [C13].Comment.Visible = True
End Sub

Private Sub ToggleButton13_Click()
 If [C14].Comment.Visible Then [C14].Comment.Visible = False Else [C14].Comment.Visible = True
End Sub

Private Sub ToggleButton14_Click()
 If [C15].Comment.Visible Then [C15].Comment.Visible = False Else [C15].Comment.Visible = True
End Sub

Private Sub ToggleButton15_Click()
 If [C16].Comment.Visible Then [C16].Comment.Visible = False Else [C16].Comment.Visible = True
End Sub

Private Sub ToggleButton16_Click()
 If [C17].Comment.Visible Then [C17].Comment.Visible = False Else [C17].Comment.Visible = True
End Sub

Private Sub ToggleButton17_Click()
 If [C18].Comment.Visible Then [C18].Comment.Visible = False Else [C18].Comment.Visible = True
End Sub

Private Sub ToggleButton18_Click()
 If [C19].Comment.Visible Then [C19].Comment.Visible = False Else [C19].Comment.Visible = True
End Sub

Private Sub ToggleButton2_Click()
 If [C3].Comment.Visible Then [C3].Comment.Visible = False Else [C3].Comment.Visible = True
End Sub

Private Sub ToggleButton3_Click()
 If [C4].Comment.Visible Then [C4].Comment.Visible = False Else [C4].Comment.Visible = True
End Sub

Private Sub ToggleButton4_Click()
 If [C5].Comment.Visible Then [C5].Comment.Visible = False Else [C5].Comment.Visible = True
End Sub

Private Sub ToggleButton5_Click()
 If [C6].Comment.Visible Then [C6].Comment.Visible = False Else [C6].Comment.Visible = True
End Sub

Private Sub ToggleButton6_Click()
 If [C7].Comment.Visible Then [C7].Comment.Visible = False Else [C7].Comment.Visible = True
End Sub

Private Sub ToggleButton7_Click()
 If [C8].Comment.Visible Then [C8].Comment.Visible = False Else [C8].Comment.Visible = True
End Sub

Private Sub ToggleButton8_Click()
 If [C9].Comment.Visible Then [C9].Comment.Visible = False Else [C9].Comment.Visible = True
End Sub

Private Sub ToggleButton9_Click()
 If [C10].Comment.Visible Then [C10].Comment.Visible = False Else [C10].Comment.Visible = True
End Sub
 

soan

XLDnaute Barbatruc
Inactif
Bonjour Yann, sousou,

réponse selon ton post #1 :

VB:
Option Explicit

Private Sub Job(cel As Range)
  cel.Comment.Visible = Not cel.Comment.Visible
End Sub

Private Sub ToggleButton1_Click()
  Job [C2]
End Sub

Private Sub ToggleButton2_Click()
  Job [C3]
End Sub

Private Sub ToggleButton3_Click()
  Job [C4]
End Sub

Private Sub ToggleButton4_Click()
  Job [C5]
End Sub

Private Sub ToggleButton5_Click()
  Job [C6]
End Sub

Private Sub ToggleButton6_Click()
  Job [C7]
End Sub

Private Sub ToggleButton7_Click()
  Job [C8]
End Sub

Private Sub ToggleButton8_Click()
  Job [C9]
End Sub

Private Sub ToggleButton9_Click()
  Job [C10]
End Sub

Private Sub ToggleButton10_Click()
  Job [C11]
End Sub

Private Sub ToggleButton11_Click()
  Job [C12]
End Sub

Private Sub ToggleButton12_Click()
  Job [C13]
End Sub

Private Sub ToggleButton13_Click()
  Job [C14]
End Sub

Private Sub ToggleButton14_Click()
  Job [C15]
End Sub

Private Sub ToggleButton15_Click()
  Job [C16]
End Sub

Private Sub ToggleButton16_Click()
  Job [C17]
End Sub

Private Sub ToggleButton17_Click()
  Job [C18]
End Sub

Private Sub ToggleButton18_Click()
  Job [C19]
End Sub

soan
 

sousou

XLDnaute Barbatruc
Re
Voici une solution à compléter
Voir l'exemple dans la feuille 1
J'utilise non pas des active x, mais des shapes,
deux tables permettant de faire la correspondance entre les cellules et les boutons
tu n'as plu qu'a copier les boutons dans la feuille et les nommer correctement
pas de code à ajouter
 

Pièces jointes

  • sousou NOTES_TEST (6).xlsm
    166.9 KB · Affichages: 6

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
314 645
Messages
2 111 536
Membres
111 185
dernier inscrit
Laurent.