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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| Option Explicit
Dim idd As Long
Dim ide As Long
Dim idr As Long
Dim nom As String
Dim pkm As Integer
Dim mfn As Byte
Dim tmf(2)
Dim tbd
Dim tbe
Dim tbr
Dim elm
Public Sub Calculs()
With ActiveSheet
.Cells(2, 5).Resize(.Cells(Rows.Count, 5).End(xlUp).Row, 4).ClearContents
Call parcours
Call résultat
Call mfc
End With
End Sub
Public Sub résultat()
Dim eec As String, nec As Byte, typ As String
idr = 1: mfn = 0: tmf(0) = "=OU(": tmf(1) = "=OU(" '$F2=""tom"";$F2=""léa"")"
For ide = 1 To UBound(tbe)
eec = " | " & tbe(ide, 1): nec = 0: mfn = IIf(mfn, 0, 1)
tmf(mfn) = tmf(mfn) & IIf(Len(tmf(mfn)) > 4, ";", "") & "$F2=""" & tbe(ide, 1) & """"
For idd = 1 To UBound(tbd)
elm = Split(tbd(idd), " ")
If elm(1) = "/" Then
nec = nec + 1
If tbe(ide, 1) <> elm(2) Then eec = eec & " | " & elm(2) Else nom = elm(2)
Else
nec = nec - 1: eec = Replace(eec, " | " & elm(2), "")
If elm(2) = tbe(ide, 1) Then tbr(idr - 1, 1) = elm(0) - pkm: Exit For
End If
If nom = tbe(ide, 1) Then
If idr > 1 Then
If tbr(idr - 1, 1) = "" Then tbr(idr - 1, 1) = elm(0) - pkm
End If
tbr(idr, 2) = tbe(ide, 1)
tbr(idr, 3) = nec
tbr(idr, 4) = Mid(eec, 4)
idr = idr + 1: pkm = elm(0)
End If
Next idd
Next ide
ActiveSheet.[E2].Resize(idr - 1, 4).Value = tbr
End Sub
Public Sub parcours()
tbe = ActiveSheet.Range("T_e").Value
ReDim tbd(1 To 1)
For ide = 1 To UBound(tbe)
tbd(UBound(tbd)) = tbe(ide, 2) & " / " & tbe(ide, 1)
ReDim Preserve tbd(1 To UBound(tbd) + 1)
tbd(UBound(tbd)) = tbe(ide, 3) & " \ " & tbe(ide, 1)
ReDim Preserve tbd(1 To UBound(tbd) + 1)
Next ide
For ide = 1 To UBound(tbd) - 1
For idd = ide To UBound(tbd) - 1
If tbd(ide) > tbd(idd) Then nom = tbd(ide): tbd(ide) = tbd(idd): tbd(idd) = nom
Next idd
elm = Split(tbd(ide), " ")
If Not IsNumeric(elm(0)) Or elm(0) = "" Then MsgBox "Donnée PK incorrecte : " & elm(0) & " pour " & elm(2): End
Next ide
ReDim tbr(1 To UBound(tbe) * 5, 1 To 4)
End Sub
Sub mfc()
With ActiveSheet.Cells(2, 5).Resize(ActiveSheet.Cells(Rows.Count, 5).End(xlUp).Row, 4)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:=tmf(1) & ")"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
End With
.FormatConditions.Add Type:=xlExpression, Formula1:=tmf(0) & ")"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.14996795556505
End With
End With
End Sub |
Partager