Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/01/2012, 12h56   #1
Candidat au titre de Membre du Club
 
Inscription : août 2007
Messages : 94
Détails du profil
Informations forums :
Inscription : août 2007
Messages : 94
Points : 14
Points : 14
Par défaut Raccourcir mon code

Bonjour qui pourrait m'aider a raccourcir mon code car procédure trop longue

merci

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
Private Sub CommandButton1_Click()
If Label10.Caption = "1" Then ' LUNDI
Calendrier.Label10.BackColor = Feuil1.Range("F6").Interior.Color
Calendrier.Label13.BackColor = Feuil1.Range("O6").Interior.Color
Calendrier.Label16.BackColor = Feuil1.Range("X6").Interior.Color
Calendrier.Label18.BackColor = Feuil1.Range("L9").Interior.Color
Calendrier.Label21.BackColor = Feuil1.Range("U9").Interior.Color
Calendrier.Label24.BackColor = Feuil1.Range("I12").Interior.Color
Calendrier.Label27.BackColor = Feuil1.Range("R12").Interior.Color
Calendrier.Label30.BackColor = Feuil1.Range("F15").Interior.Color
Calendrier.Label33.BackColor = Feuil1.Range("O15").Interior.Color
Calendrier.Label36.BackColor = Feuil1.Range("X15").Interior.Color
Calendrier.Label39.BackColor = Feuil1.Range("l18").Interior.Color
End If
If Label11.Caption = "1" Then ' MARDI
Calendrier.Label11.BackColor = Feuil1.Range("I6").Interior.Color
Calendrier.Label14.BackColor = Feuil1.Range("R6").Interior.Color
Calendrier.Label17.BackColor = Feuil1.Range("F9").Interior.Color
Calendrier.Label20.BackColor = Feuil1.Range("O9").Interior.Color
Calendrier.Label23.BackColor = Feuil1.Range("X9").Interior.Color
Calendrier.Label26.BackColor = Feuil1.Range("L12").Interior.Color
Calendrier.Label29.BackColor = Feuil1.Range("U12").Interior.Color
Calendrier.Label32.BackColor = Feuil1.Range("I15").Interior.Color
Calendrier.Label35.BackColor = Feuil1.Range("R15").Interior.Color
Calendrier.Label38.BackColor = Feuil1.Range("F18").Interior.Color
Calendrier.Label41.BackColor = Feuil1.Range("O18").Interior.Color
End If
If Label12.Caption = "1" Then ' MERCREDI
Calendrier.Label12.BackColor = Feuil1.Range("L6").Interior.Color
Calendrier.Label15.BackColor = Feuil1.Range("U6").Interior.Color
Calendrier.Label18.BackColor = Feuil1.Range("I9").Interior.Color
Calendrier.Label21.BackColor = Feuil1.Range("R9").Interior.Color
Calendrier.Label24.BackColor = Feuil1.Range("F12").Interior.Color
Calendrier.Label27.BackColor = Feuil1.Range("O12").Interior.Color
Calendrier.Label30.BackColor = Feuil1.Range("X12").Interior.Color
Calendrier.Label33.BackColor = Feuil1.Range("L15").Interior.Color
Calendrier.Label36.BackColor = Feuil1.Range("U15").Interior.Color
Calendrier.Label39.BackColor = Feuil1.Range("I18").Interior.Color
Calendrier.Label42.BackColor = Feuil1.Range("R18").Interior.Color
End If
End Sub
ceci n'est que le début il faut que je fasse c'estte procédur pour fevrier mars etc.....

merci merci
UDSP50 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/01/2012, 13h32   #2
Membre Expert
 
Avatar de ZebreLoup
 
Homme Sebastien L
Ingénieur Financier
Inscription : mars 2010
Messages : 880
Détails du profil
Informations personnelles :
Nom : Homme Sebastien L
Âge : 33
Localisation : France, Val de Marne (Île de France)

Informations professionnelles :
Activité : Ingénieur Financier
Secteur : Finance

Informations forums :
Inscription : mars 2010
Messages : 880
Points : 1 867
Points : 1 867
Alors là comme ça, je ne vois pas trop ce qu'on peut faire pour toi. Il faut expliquer un peu plus ce que doit faire la procédure, s'il y a une logique dans les nom des label et les cellules de référence pour les couleurs...

Enfin, première remarque, quand tu utilises des labels autrement que pour seulement afficher du texte qui ne change pas, il vaut mieux leur donner un nom explicite plutôt que de garder label1, label2, ...
__________________
« Compter en octal, c’est comme compter en décimal, si on n’utilise pas ses pouces » - Tom Lehrer
« Il est assez difficile de trouver une erreur dans son code quand on la cherche. C’est encore bien plus dur quand on est convaincu que le code est juste. » - Steve McConnell
ZebreLoup est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h51.


 
 
 
 
Partenaires

Hébergement Web