Bouton associé a deux macros

ashile -  
pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   -
Bonjour,
j'aimerai bien realiser un bouton qui realise deux fonctions(une fois masquer les ligne et l autre afficher les lignes masquées ) differentes voici la solution que j ai trouvé mais il y a une erreur lors de la compilation apparament un probleme avec la fonction ActiveSheet
voici mon code
Sub masquer_ligne()
Dim cel As Range
For Each cel In Range("G1:G90")
If cel = "0" Then
cel.EntireRow.Hidden = True
End If
Next
ActiveSheet.Shapes("MonBouton").Select
Selection.Characters.Text = "Masquer"
Range("Q2").Select
End Sub
Sub Afficher_ligne()
Dim cel As Range
For Each cel In Range("G1:G90")
If cel = "0" Then
cel.EntireRow.Hidden = False
End If
Next
ActiveSheet.Shapes("MonBouton").Select
Selection.Characters.Text = "Afficher"
Range("Q2").Select
End Sub


merci d'avance

2 réponses

  1. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
     
    Bonjour,

    mais il y a une erreur lors de la compilation apparament un probleme avec la fonction ActiveSheet
    Ce n'est pas ActiveSheet qui bloque, mais Characters.Text. Elle ne se rapporte pas au Shape, mais à la propriété TextFrame des Shapes.

    Utilise un ToogleButton
    Ou alors, utilises un code qui affiche ou masque selon le "caption" de ton bouton :
    Sub Afficher_Masquer_ligne()
    Dim cel As Range, Test As Boolean
    
    If ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = "Masquer" Then
        Test = True
        ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = "Afficher"
    Else
        Test = False
        ActiveSheet.Shapes("Button 1").TextFrame.Characters.Text = "Masquer"
    End If
    For Each cel In Range("G1:G90")
        If cel = "0" Then
            cel.EntireRow.Hidden = Test
        End If
    Next
    Range("Q2").Select
    End Sub
     

    0