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 86 87 88 89 90 91 92 93
| Option Explicit
Dim idd As Long
Dim ide As Long
Dim idr As Long
Dim nom As String
Dim mfn As Byte
Dim tmf(2)
Dim tbd
Dim tbe
Dim tbr
Dim elm
Public Sub Calculs()
With ActiveSheet
.Cells(2, 6).Resize(.Cells(Rows.Count, 6).End(xlUp).Row, 7).ClearContents
Call parcours
Call résultat
Call mfc
End With
End Sub
Public Sub résultat()
Dim eec As String, nec As Byte, nkm As Integer, pkm As Double, nok As Boolean
idr = 1: mfn = 0: tmf(0) = "=OU(": tmf(1) = "=OU("
For ide = 2 To UBound(tbe)
eec = "": nec = 0: mfn = IIf(mfn, 0, 1): nok = False: nkm = 0: pkm = 0
tmf(mfn) = tmf(mfn) & IIf(Len(tmf(mfn)) > 4, ";", "") & "$G2=""" & tbe(ide, 1) & """"
For idd = 1 To UBound(tbd) - 1
elm = Split(tbd(idd), " ")
If elm(1) = "/" Then
nec = nec + 1: eec = eec & "| " & elm(2) & " ": If elm(2) = tbe(ide, 1) Then nok = True
Else
nec = nec - 1: eec = Replace(eec, "| " & elm(2) & " ", "")
End If
If nok Then
If tbd(idd + 1) = "" Then
tbr(idr, 1) = Split(tbd(idd) & " ", " ")(0) - Split(tbd(idd - 1) & " ", " ")(0)
Else
tbr(idr, 1) = Split(tbd(idd + 1) & " ", " ")(0) - Split(tbd(idd) & " ", " ")(0)
End If
nkm = nkm + tbr(idr, 1)
tbr(idr, 2) = tbe(ide, 1)
tbr(idr, 3) = nec
tbr(idr, 4) = Mid(eec, 3)
tbr(idr, 6) = tbr(idr, 1) * tbe(ide, 4) * IIf(nec = 1, 0.9, IIf(nec = 2, 0.77, 0.63))
pkm = pkm + tbr(idr, 6)
If tbr(idr, 1) > 0 Then idr = idr + 1
If Split(tbd(idd + 1) & " ", " ")(2) = tbe(ide, 1) And Split(tbd(idd + 1) & " ", " ")(1) = "\" Then
tbr(idr - 1, 5) = nkm
tbr(idr - 1, 7) = pkm
Exit For
End If
End If
Next idd
Next ide
ActiveSheet.[F2].Resize(idr - 1, UBound(tbr, 2)).Value = tbr
End Sub
Public Sub parcours()
tbe = ActiveSheet.Range("A1").CurrentRegion.Value
ReDim tbd(1 To 1)
For ide = 2 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) * 15, 1 To 8)
End Sub
Sub mfc()
With ActiveSheet.Cells(2, 6).Resize(ActiveSheet.Cells(Rows.Count, 6).End(xlUp).Row - 1, 7)
.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
.Color = 44999
.TintAndShade = 0
End With
End With
End Sub |
Partager