Résolu : Simplification de formule
Bonsoir, kjin, sousou, tibo.
Votre fonction fonctionne parfaitement.
C'est moi qui ai mal décrit mon environnement, et tibo a raison : avec un fichier, c'est plus clair.
Le fichier, réduit à sa plus simple expression, faisant 74 Ko, je ne peux donc le joindre.
Son adresse sur cjoint :
http://cjoint.com/?0bywUQDWENj
Je vous adresse cependant la macro d'un autre internaute qui résout mon problème.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range) 'GuyXL, Développer.net
Dim oWsHC As Worksheet 'feuille Horaire Classe
Dim oWsHN As Worksheet 'feuille Horaire Nom
Dim vSNom As String 'la condition
Dim vLDLg As Long 'la dernière ligne du tableau Horaire Classe
Dim vbLEc As Byte 'ligne d'écriture
Dim i As Byte
Dim j As Long
If Target.Address = "$AH$1" And Target.Count = 1 Then 'si l'on change la valeur de Nom
vSNom = Cells(1, 34) 'initialisation du nom
'dernière ligne tableau
vLDLg = Cells(Rows.Count, 1).End(xlUp).Row
If (vLDLg - 2) Mod 9 <> 0 Then 'contrôle : ce tableau doit contenir un multiple de 9 lignes
MsgBox "Anomalie nombre de ligne tableau Matière-Prof"
Exit Sub
End If
'objets
Set oWsHC = ActiveSheet
Set oWsHN = Worksheets("Horaire Nom")
'nettoyage feuille Horaire Nom
oWsHN.Range("B3:C11, E3:F11, H3:I11, B15:C23, E15:F23, H15:I23").ClearContents
'oWsHN.Range("B3:B11, E3:E11, H3:H11, B15:B23, E15:E23, H15:H23").Interior.ColorIndex = 4
'oWsHN.Range("C3:C11, F3:F11, I3:I11, C15:C23, F15:F23, I15:I23").Interior.ColorIndex = 5
'traitement
For i = 5 To 20 Step 3 'pour chaque jour
For j = 3 To vLDLg 'pour chaque ligne
If Cells(j, i) = vSNom Then
'calcul de la ligne d'écriture
Select Case i
Case 5, 8, 11
vbLEc = j - 9 * Int((j - 3) / 9)
Case 14, 17, 20
vbLEc = j - 9 * Int((j - 3) / 9) + 12
End Select
Select Case i
Case 5, 8, 11
'classes
If oWsHN.Cells(vbLEc, i - 3) = "" Then
oWsHN.Cells(vbLEc, i - 3) = Cells(j, 2) '1ère occurence
Else
oWsHN.Cells(vbLEc, i - 3) = oWsHN.Cells(vbLEc, i - 3) & "," & Cells(j, 2) 'occurences suivantes
'oWsHN.Cells(vbLEc, i - 3).Interior.ColorIndex = 3 'coloriage alerte plusieurs classes
End If
'matières
If oWsHN.Cells(vbLEc, i - 2) = "" Then
oWsHN.Cells(vbLEc, i - 2) = Cells(j, i - 1) '1ère occurence
Else
'occurences suivantes, contrôle matières différentes pour même horaire
If oWsHN.Cells(vbLEc, i - 2) <> Cells(j, i - 1) Then
oWsHN.Cells(vbLEc, i - 2) = "Anomalie"
'oWsHN.Cells(vbLEc, i - 2).Interior.ColorIndex = 3
End If
End If
Case 14, 17, 20
'classes
If oWsHN.Cells(vbLEc, i - 12) = "" Then
oWsHN.Cells(vbLEc, i - 12) = Cells(j, 2) '1ère occurence
Else
oWsHN.Cells(vbLEc, i - 12) = oWsHN.Cells(vbLEc, i - 12) & "," & Cells(j, 2) 'occurences suivantes
'oWsHN.Cells(vbLEc, i - 12).Interior.ColorIndex = 3 'coloriage alerte plusieurs classes
End If
'matières
If oWsHN.Cells(vbLEc, i - 11) = "" Then
oWsHN.Cells(vbLEc, i - 11) = Cells(j, i - 1) '1ère occurence
Else
'occurences suivantes, contrôle matières différentes pour même horaire
If oWsHN.Cells(vbLEc, i - 11) <> Cells(j, i - 1) Then
oWsHN.Cells(vbLEc, i - 11) = "Anomalie"
'oWsHN.Cells(vbLEc, i - 11).Interior.ColorIndex = 3
End If
End If
End Select
End If
Next j
Next i
End If
'oWsHN.Activate
Set oWsHN = Nothing
Set oWsHC = Nothing
End Sub
Je vous remercie sincèrement, ainsi que les autres membres de ce forum, pour l'aide apportée.
Bien cordialement,