Appliquer un cde VBA sur certaines feuilles et pas d'autres
madjon6
Messages postés
270
Statut
Membre
-
eriiic Messages postés 25847 Statut Contributeur -
eriiic Messages postés 25847 Statut Contributeur -
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.
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:
- Appliquer un cde VBA sur certaines feuilles et pas d'autres
- Comment faire un livret avec des feuilles a4 - Guide
- Bruler des feuilles de laurier - Guide
- Desinstaller application sur windows - Guide
- Comment supprimer une application préinstallée sur android - Guide
- Fusionner feuilles excel - Guide
2 réponses
Bonjour madjon6,
Je te propose ce code VBA :
Si ton problème est réglé, merci d'aller en haut de page
pour cliquer sur « Marquer comme résolu ».
Cordialement. :)
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. :)
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
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
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. :)