Fonction For et Sheets

Bonjour au Forum

Est il possible d'utiliser avec la commande Sheets avec la boucle for ?

Car mes feuilles ont le meme nom à une acrémentation pres

exemple au lieu de :

Sheets("Feuil1")

ce serrait :

For i=2 to 5

Sheets("Feuille"i).Select

Sub SyntheseTRS()

For i=2 to 5
If Sheets("Synthese_TRS S18-"i).Visible = False Then
Sheets("Synthese_TRS S18-"i).Visible = True
Else: GoTo Masquer
End If

Masquer:
If Sheets("Synthese_TRS S18-"i).Visible = True Then Sheets("Synthese_TRS S18-"i).Visible = False

End Sub

Bonjour,

Sub SyntheseTRS()
    For i = 2 To 5
        With Sheets("Synthese_TRS S18-" & i)
            .Visible = IIf(.Visible = xlSheetVisible, xlSheetHidden, xlSheetVisible)
        End With
    Next i
End Sub

Cordialement.

Effectivement ca marche c parfait .

Maintenant j'aurais besoin de la meme chose mais avec la variable au milieu de la feuille

Sub AfficherAS18()

For i = 2 To 6

If Sheets("S18-" & i & "ARRET ABB 1&2").Visible = False Then
Sheets("S18-" & i & "ARRET ABB 1&2").Visible = True
Else: GoTo Masquer
End If

Next

If Sheets("S18-Total ARRET ABB 1&2").Visible = False Then
Sheets("S18-Total ARRET ABB 1&2").Visible = True
Exit Sub
Else: GoTo Masquer
End If

Masquer:

For i = 2 To 6

If Sheets("S18-" & i & "ARRET ABB 1&2").Visible = True Then Sheets("S18-" & i & "ARRET ABB 1&2").Visible = False
Next
If Sheets("S18-Total ARRET ABB 1&2").Visible = True Then Sheets("S18-Total ARRET ABB 1&2").Visible = False

End Sub

Quelqu'un voit t'il mon erreur ? Ma feuille se Nomme : S18-2 ARRET ABB 1&2 , ect...

Commence par supprimer le code inutile et écris de façon économique et logique...

Desoler je debute , Je dois faire pas mal de chose inutile encore .

Bref j'ai modifier et ca me donne ca

Sub AfficherAS18()

 For i = 2 To 6
        With Sheets("S18-" & i & "ARRET ABB 1&2")
            .Visible = IIf(.Visible = xlSheetVisible, xlSheetHidden, xlSheetVisible)
        End With
    Next i

 With Sheets("S18-Total ARRET ABB 1&2")
.Visible = IIf(.Visible = xlSheetVisible, xlSheetHidden, xlSheetVisible)
End With

End Sub

Mais je dois avoir une erreur de syntaxe car il en veut pas il me dit que l'indice n'appartient pas a la sélection a la ligne

 With Sheets("S18-" & i & "ARRET ABB 1&2")

Edit : J'ai trouver mon erreur , J'ai oublié de mettre l'espace ("S18-" & i & " ARRET ABB 1&2")

Merci pour ton aide ca ma évité pas mal de ligne inutile

Rechercher des sujets similaires à "fonction sheets"