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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| Sub calculecart()
Dim i, j, k, m, n, o, p, q, r, y, z, DernCol1, DernCol2, DernLig1, DernLig2, ecart, ecart2, besoin1, besoin2, besoin3, besoin4 As Double
Dim date1 As Date
Dim equip, nom As String
z = ThisWorkbook.Sheets.Count
For y = 2 To z
nom = Sheets(y).Name
With Worksheets(y)
i = 6
While Not IsEmpty(.Cells(6, i))
i = i + 2
Wend
i = i - 2
MsgBox (i)
j = i
While IsEmpty(.Cells(2, j))
j = j - 1
Wend
date1 = .Cells(2, j).Value
k = 6
While Not IsEmpty(.Cells(k, 3))
k = k + 1
Wend
k = k - 1
While j <> 5
For l = 6 To k
equip = .Cells(l, 3).Value
With Worksheets("BILAN")
DernCol1 = .Range("RCZ4").End(xlToLeft).Column
DernLig1 = .Range("B65536").End(xlUp).Row
n = 3
For m = 6 To DernLig1
If .Cells(m, 2).Value = equip Then
For n = 3 To DernCol1
If .Cells(4, n).Value = date1 Then
With Worksheets(y)
DernLig2 = .Range("C65536").End(xlUp).Row
For p = DernLig2 To 1 Step -1
If .Cells(p, 3).Value = "réel" Then
For q = p + 1 To DernLig2
If .Cells(q, 3).Value = equip Then
besoin1 = 0
For o = j To i Step 2
besoin1 = besoin1 + .Cells(m, 4).Value * .Cells(q, o).Value * .Cells(q, o + 1).Value
Next o
Else
End If
Next
Else
End If
Next
besoin2 = 0
For o = j To i Step 2
besoin2 = besoin2 + .Cells(m, 4).Value * .Cells(m, o).Value * .Cells(m, o + 1).Value
Next o
End With
ecart = besoin1 - besoin2
.Cells(m, n).Value = ecart
Else
End If
Next
Else
End If
Next
End With
Next
For q = DernLig2 To 1 Step -1
If .Cells(q, 3).Value = "BESOIN SAMEDI" Then
besoin3 = 0
For o = j To i Step 2
besoin3 = besoin3 + .Cells(q, o).Value + .Cells(q + 1, o).Value + .Cells(q + 2, o).Value
Next o
Else
End If
If .Cells(q, 3).Value = "réel" Then
For r = q To DernLig2
If .Cells(r, 3).Value = "BESOINS AUTRES" Then
besoin4 = 0
For o = j To i Step 2
besoin4 = besoin4 + .Cells(r, o).Value
Next o
Else
End If
Next
Else
End If
Next
ecart2 = besoin4 - besoin3
With Worksheets("BILAN")
For n = 3 To DernCol1
If .Cells(4, n).Value = date1 Then
.Cells(11, n) = ecart2
Else
End If
Next
End With
i = j - 1
j = i
If j <> 5 Then
While IsEmpty(.Cells(2, j))
j = j - 1
Wend
date1 = .Cells(2, j).Value
Else
End If
Wend
End With
Next
End Sub |
Partager