Conseil macro pour la création d'un planning

Nico67800

XLDnaute Nouveau
Bonjour à tous,

Dans le cadre de la création d’un planning sur Excel pour le travail, j’ai besoin d’une macro qui permet de changer une zone de couleur en fonction d’un champ.

Mes connaissances en VBA étant très limitées j’ai réussi à bidouiller une macro mais malheureusement ça ne fait pas totalement mon bonheur.
Ce champ est limité à 10 possibilités proposées sous forme d’un menu déroulant.
J’ai crée une macro qui permet de faire ça (voir ci-dessous)
Le principe est simple :
La cellule I5 propose les champs suivants :
-disponible, intervention confirmée, intervention à confirmer, atelier, formation, congés, jour férié, intervention étranger confirmée, intervention étranger à confirmer, divers.
Une fois le champ sélectionné, j’appuie sur un bouton lié à la macro qui colore ma sélection « I2 à I8 ». Chaque champ est lié à une couleur.
En théorie ça fonctionne, mais cette méthode ne peut être appliquée à grande échelle. En effet ça nécessiterait de faire une macro par personne par semaine soit plus de 500.

Est-il possible de réutiliser ma macro et de « l’automatiser » pour n’en faire qu’une par personne ?
J’ai juste besoin de changer à chaque fois le champ et la plage correspondante et j’aimerais éviter de faire la même opération pour chaque jour.
Vous trouverez ici le fichier Excel que j’utilise : , ça sera probablement beaucoup plus parlant de jeter un coup d’œil au fichier.
Juste en dessous vous pouvez voir en exemple ma macro utilisée :

Sub couleurs_s1()
' couleurs_s1 Macro
'Dim Ref As Range
Set Ref = ActiveCell
If Range("I5") = "congés" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
End If
If Range("I5") = "formation" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
If Range("I5") = "atelier" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
If Range("I5") = "intervention confirmée" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
If Range("I5") = "intervention à confirmer" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
If Range("I5") = "disponible" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
If Range("I5") = "jour férié" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
End If
If Range("I5") = "intervention étranger à confirmer" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.79981688894314
.PatternTintAndShade = 0
End With
End If

If Range("I5") = "intervention étranger confirmée" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
End If

If Range("I5") = "divers" Then
Range("I2:I8").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Ref.Select
End Sub

Merci beaucoup pour votre aide !
Nicolas
 

Statistiques des forums

Discussions
312 223
Messages
2 086 403
Membres
103 201
dernier inscrit
centrale vet