Appliquer un cde VBA sur certaines feuilles et pas d'autres

Fermé
madjon6 Messages postés 262 Date d'inscription mercredi 2 janvier 2008 Statut Membre Dernière intervention 30 novembre 2017 - 28 nov. 2016 à 12:24
eriiic Messages postés 24570 Date d'inscription mardi 11 septembre 2007 Statut Contributeur Dernière intervention 23 avril 2024 - 28 nov. 2016 à 19:21
Bonjour,

Je souhaite appliquer un code vba sur certaines feuilles pas d'autres.

Pouvez-vous m'aider svp ?
Exemple :

Si la feuille "Param" et la feuille "Budget" existe alors ne rien faire sur ces feuilles sinon appliquer le code sur toutes les autres feuilles.

Merci pour votre aide.
A voir également:

2 réponses

Utilisateur anonyme
28 nov. 2016 à 12:55
Bonjour madjon6,

Je te propose ce code VBA :


Option Explicit

Sub Essai()
  Dim FX As Worksheet
  For Each FX In Worksheets
    If FX.Name <> "Param" And FX.Name <> "Budget" Then
      ' Mettre ici le travail à faire pour
      ' toutes les autres feuilles
    End If
  Next FX
End Sub


Si ton problème est réglé, merci d'aller en haut de page
pour cliquer sur « Marquer comme résolu ».

Cordialement.  :)
 
0
madjon6 Messages postés 262 Date d'inscription mercredi 2 janvier 2008 Statut Membre Dernière intervention 30 novembre 2017 79
28 nov. 2016 à 14:01
Bonjour Merci pour votre retour mais cela ne fonctionne pas je ne sais pas pourquoi

voici mon code entier :

Sub Modification_manuelle_tx()
Dim FX As Worksheet
For Each FX In Worksheets
If FX.Name <> "Paramètres" And FX.Name <> "Budget" And FX.Name <> "Eolution_simulation " And FX.Name <> "Tableau Consolidé" Then Else

'
Range("AC5").Select
ActiveCell.FormulaR1C1 = "=Paramètres!R5C1"
Range("AD5").Select
ActiveCell.FormulaR1C1 = "=Paramètres!R5C2"
Range("AF5").Select
ActiveCell.FormulaR1C1 = "=Paramètres!R5C3"
Range("AG5").Select
ActiveCell.FormulaR1C1 = "=Paramètres!RC[-29]"
ActiveCell.FormulaR1C1 = "=Paramètres!R5C4"
Range("AE7").Select
ActiveSheet.Shapes.AddTextEffect(msoTextEffect27, "Les taux et poids des groupe, entité ont été récupérés depuis l'onglet paramètres", "+mn-lt", _
12, msoTrue, msoFalse, 831.8231496063, 115.272992126).Select
Selection.ShapeRange.IncrementLeft 74.3750393701
Selection.ShapeRange.IncrementTop -12.5
Selection.ShapeRange.IncrementLeft -1.25
Selection.ShapeRange.IncrementTop -2.772992126



With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 3).Font
.Bold = msoTrue
.Caps = msoNoCaps
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Shadow.Type = msoShadow21
.Shadow.Visible = msoTrue
.Shadow.Style = msoShadowStyleOuterShadow
.Shadow.Blur = 6.2992125984
.Shadow.OffsetX = 0.3292235064
.Shadow.OffsetY = 3.1323524264
.Shadow.RotateWithShape = msoTrue
.Shadow.ForeColor.RGB = RGB(0, 0, 0)
.Shadow.Transparency = 0.6999999881
.Shadow.Size = 100
.Fill.Visible = msoTrue
.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent6
.Fill.ForeColor.TintAndShade = 0.1000000238
.Fill.ForeColor.Brightness = 0
.Fill.BackColor.ObjectThemeColor = msoThemeColorAccent6
.Fill.BackColor.TintAndShade = 0.1000000238
.Fill.BackColor.Brightness = 0
.Fill.TwoColorGradient msoGradientHorizontal, 3
.Size = 54
.Line.Visible = msoFalse
.Name = "+mn-lt"
.Spacing = 0
End With
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(4, 79).Font
.BaselineOffset = 0
.Bold = msoTrue
.Caps = msoNoCaps
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Shadow.Type = msoShadow21
.Shadow.Visible = msoTrue
.Shadow.Style = msoShadowStyleOuterShadow
.Shadow.Blur = 6.2992125984
.Shadow.OffsetX = 0.3292235064
.Shadow.OffsetY = 3.1323524264
.Shadow.RotateWithShape = msoTrue
.Shadow.ForeColor.RGB = RGB(0, 0, 0)
.Shadow.Transparency = 0.6999999881
.Shadow.Size = 100
.Fill.Visible = msoTrue
.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent6
.Fill.ForeColor.TintAndShade = 0.1000000238
.Fill.ForeColor.Brightness = 0
.Fill.BackColor.ObjectThemeColor = msoThemeColorAccent6
.Fill.BackColor.TintAndShade = 0.1000000238
.Fill.BackColor.Brightness = 0
.Fill.TwoColorGradient msoGradientHorizontal, 3
.Size = 54
.Line.Visible = msoFalse
.Name = "+mn-lt"
.Spacing = 0
End With

Selection.ShapeRange.TextFrame2.TextRange.Font.Size = 12

Selection.ShapeRange.IncrementTop 15.8750393701
Range("X5:Z5").Select
End If
Next FX
End Sub
0
Utilisateur anonyme
28 nov. 2016 à 16:02
 
Sans rentrer dans le détail de ton code VBA :

1) Attention aux noms de feuilles ! Je pense que ce n'est pas "Eolution_simulation "
    mais "Evolution_simulation" : avec un v, et sans espace à la fin.

==================================

2) Pour les instructions du travail à faire, 2 possibilités selon qu'on utilise ou non
    un Select pour aller sur la feuille (on choisit cela selon le travail à faire).

-----------------------------------------------------------

a) Sans Select


Option Explicit

Sub Essai()
  Dim FX As Worksheet
  For Each FX In Worksheets
    If FX.Name <> "Param" And FX.Name <> "Budget" Then
      FX.[B2] = "X": FX.[C2] = "Y": FX.[D2] = "Z"
    End If
  Next FX
End Sub


OU


Option Explicit

Sub Essai()
  Dim FX As Worksheet
  For Each FX In Worksheets
    With FX
      If .Name <> "Param" And .Name <> "Budget" Then
        .[B2] = "X": .[C2] = "Y": .[D2] = "Z"
      End If
    End With
  Next FX
End Sub


-----------------------------------------------------------

b) Avec Select


Option Explicit

Sub Essai()
  Dim FX As Worksheet, chn As String: Application.ScreenUpdating = False
  For Each FX In Worksheets
    chn = FX.Name
    If chn <> "Param" And chn <> "Budget" Then
      FX.Select
      [B2] = "X": [C2] = "Y": [D2] = "Z"
    End If
  Next FX
End Sub


Le Select est en ligne #9 : FX.Select

==================================

Je te laisse voir tout ça, et adapter ton code VBA.  :)
 
0
eriiic Messages postés 24570 Date d'inscription mardi 11 septembre 2007 Statut Contributeur Dernière intervention 23 avril 2024 7 215
Modifié par eriiic le 28/11/2016 à 19:26
Bonjour,

@ madjon6
Pourquoi avoir ajouté Else juste après le Then ???
eric

edit : utilise l'icone <> pour rendre la lecture du code plus agréable stp
0