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
| Private Sub MG12()
Dim i As Integer
Dim j&, jj&
With Sheets("Cout")
'Création du 12Mg, ce code repère si il y a 2 "YTD" auquel cas il ajoute une colonne après
For n = Cells(1, Columns.Count).End(xlToLeft).Column To 3 Step -1
If Left(Cells(1, n), 10) Like "YTD *" And Left(Cells(1, n - 1), 10) Like "YTD *" And Left(Cells(1, n), 11) = Left(Cells(1, n - 1), 11) Then
Columns(n + 1).Insert Shift:=xlShiftToRight
jj = Cells.Find("*", , , , xlByColumns, xlPrevious).Column 'Dernière colonne
For j = 3 To jj
If Cells(1, j).Value = "Réel " & Right(Cells(1, n - 1), 4) Then Exit For
Next
'Écriture 12Mg en entête de la colonne insérée
Cells(1, n + 1).Value = "12mg " & Right(Cells(1, n), 7)
'Calcul des cellules de la colonne 12Mg
For i = 2 To 53
Range(Cells(i, n + 1), Cells(i, n + 1)).Formula = Cells(i, j) + Cells(i, n) - Cells(i, n - 1)
Next i
' Calcul du critete % ASS de la colonne 12Mg
For i = 4 To 53 Step 13
Range(Cells(i, n + 1), Cells(i, n + 1)).Formula = (Cells((i - 1), 7) + Cells((i - 1), n) - Cells((i - 1), n - 1)) / ((Cells((i + 10), 4) + Cells((i + 10), n) - Cells((i + 10), n - 1)))
Next i
' Calcul du critere % E/R de la colonne 12Mg
For i = 8 To 53 Step 13
Range(Cells(i, n + 1), Cells(i, n + 1)).Formula = (Cells((i - 3), 7) + Cells((i - 3), n) - Cells((i - 3), n - 1)) / ((Cells((i + 6), 4) + Cells((i + 6), n) - Cells((i + 6), n - 1)))
Next i
End If
Next
End With
End Sub |
Partager