J'ai créé une macro dans excel qui fait que si la cellule 6 et la cellule 12 contiennent le prénom Alain, un message d'erreur apparaît. Idem pour les cellules 6 et 18, 6 et 24, 6 et 30, ...
Comment faire pour automatiser la procédure sans devoir retaper chaque fois les lignes ElseIF ... ?
Ci-dessous la macro
Merci d'avance
For li_col = 3 To 26
If Cells(6, li_col).Value "Alain" And Cells(12, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(18, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(24, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(30, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(36, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")
For li_col = 3 To 26 'Parcourt les colonnes C à Z
For i = 9 To 401 Step 8
If Cells(i, li_col).Value = "SJ 2" Then
Cells(470, li_col).Value = Cells(i - 1, 1).Value
Cells(471, li_col).Value = Cells(i, 1).Value
Cells(472, li_col).Value = Cells(i + 1, li_col).Value
Cells(473, li_col).Value = Cells(i - 1, li_col).Value
Cells(474, li_col).Value = Cells(i + 6, li_col).Value
End If
Next
Next
If Cells(6, li_col).Value "Alain" And Cells(j, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")
End If
Next j
Next li_col
Manu -------------------------------------------
Une question bien posée, c'est une chance de réponse bien adaptée.
Grand merci Manu ;-) mais je n'ai pas été tout à fait complet !
Si je veux en plus comparer la cellule 12 à la 6, 18, 24, 36 et la cellule 18 à la 6, 12, 24, 36, comment faire ?
Comme ci-dessous:
If Cells(6, li_col).Value "Alain" And Cells(12, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(18, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(24, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(30, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(36, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(42, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(48, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(54, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(6, li_col).Value "Alain" And Cells(60, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(12, li_col).Value "Alain" And Cells(18, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(12, li_col).Value "Alain" And Cells(24, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(12, li_col).Value "Alain" And Cells(30, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(12, li_col).Value "Alain" And Cells(36, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(12, li_col).Value "Alain" And Cells(42, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(12, li_col).Value "Alain" And Cells(48, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(12, li_col).Value "Alain" And Cells(54, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(12, li_col).Value "Alain" And Cells(60, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(18, li_col).Value "Alain" And Cells(24, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(18, li_col).Value "Alain" And Cells(30, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(18, li_col).Value "Alain" And Cells(36, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(18, li_col).Value "Alain" And Cells(42, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(18, li_col).Value "Alain" And Cells(48, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(18, li_col).Value "Alain" And Cells(54, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")ElseIf Cells(18, li_col).Value "Alain" And Cells(60, li_col).Value "Alain" Then
MsgBox ("Erreur ! Alain apparaît plusieurs fois à 8h30")
Message="Erreur ! Alain apparaît plusieurs fois à 8h30"
For i=12 to 60 Step 6 If Cells(6, li_col).Value "Alain" And Cells(i, li_col).Value "Alain" Then MsgBox (Message)
Next
For i=18 to 60 Step 6 If Cells(12, li_col).Value "Alain" And Cells(i, li_col).Value "Alain" Then MsgBox (Message)
Next
For i=24 to 60 Step 6 If Cells(18, li_col).Value "Alain" And Cells(i, li_col).Value "Alain" Then MsgBox (Message)
Next
[mailto:It@li It@li]@
Vous n’avez pas trouvé la réponse que vous recherchez ?
Je voudrais que si "SJ 1" est entré en (9, li_col), (17_col), (25_col),..., le contenu de certaines cellules s'affichent en (465, li_col), (466, li_col), (467, li_col), (468, li_col), (469, li_col).
Voici ci-dessous la macro que j'ai faite. Il y a sans doute moyen de la raccourcir en utilisant des boucles. Pouvez-vous me donner un coup de main ?
Coches Reponse Acceptée si ta premiére Question est Resolue !
Non ta seconde Macro Essayes :
For li_col = 3 To 26 'Parcourt les colonnes C à Z
k = 0
For i = 9 To 33 Step 8
If Cells(i, li_col).Value = "SJ 1" Then
Cells(465, li_col).Value = Cells(8 + k, 1).Value
Cells(466, li_col).Value = Cells(9 + k, 1).Value
Cells(467, li_col).Value = Cells(10 + k, li_col).Value
Cells(468, li_col).Value = Cells(8 + k, li_col).Value
Cells(469, li_col).Value = Cells(15 + k, li_col).Value
k = k + 8
End If
Next
Next