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
| Sub calCoeff()
'déclaration des variables
Dim a As Double, b As Double
Dim Sx As Double, Sy As Double, Sx2 As Double, Sy2 As Double
Dim Sxy As Double, mx As Double, my As Double
Dim i As Integer, n As Integer
Dim DerLig As Long
' initialisation des données
Sx = 0
Sy = 0
Sx2 = 0
Sxy = 0
mx = 0
my = 0
n = 0
'1ere boucle de traitement
With Worksheets("CoefSaisonnier")
DerLig = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To DerLig
Sx = Sx + .Cells(i, 1).Value
Sy = Sy + .Cells(i, 2).Value
Sx2 = Sx2 + .Cells(i, 1).Value ^ 2
Sy2 = Sy2 + .Cells(i, 2).Value ^ 2
Sxy = Sxy + .Cells(i, 1).Value * .Cells(i, 2).Value
.Cells(i, 3).Value = .Cells(i, 1).Value * .Cells(i, 2).Value
.Cells(i, 4).Value = .Cells(i, 1).Value ^ 2
n = n + 1
Next i
' calcul des moyennes x et y
mx = Sx / n
my = Sy / n
' calcul de a, b et r
a = (Sxy - n * mx * my) / (Sx2 - n * mx ^ 2)
b = my - a * mx
' affichage de la droite d'équation
If b > 0 Then
.Cells(13, 8) = "y = " & Format(a, "### ##0.000") _
& " x +" & Format(b, "### ##0.00")
End If
If b < 0 Then
.Cells(13, 8) = "y = " & Format(a, "### ##0.000") _
& " x " & Format(b, "### ##0.00")
End If
' affichage des premiers résultats
.Cells(4, 8).Value = a
.Cells(5, 8).Value = b
.Cells(6, 8).Value = mx
.Cells(7, 8).Value = my
.Cells(8, 8).Value = n
.Cells(9, 8).Value = Sx
.Cells(10, 8).Value = Sy
.Cells(11, 8).Value = Sxy
.Cells(12, 8).Value = Sx2
'2eme boucle de traitement
For i = 2 To DerLig
.Cells(i, 5).Value = .Cells(4, 8).Value * .Cells(i, 1).Value + .Cells(5, 8).Value
If .Cells(i, 5).Value <> 0 Then
.Cells(i, 6).Value = .Cells(i, 2).Value / .Cells(i, 5).Value
End If
Next i
'calcul des Coefficients saisonniers trimestriels
Trim1 = (.Range("F2").Value + .Range("F6").Value + .Range("F10").Value) / 3
Trim2 = (.Range("F3").Value + .Range("F7").Value + .Range("F11").Value) / 3
Trim3 = (.Range("F4").Value + .Range("F8").Value + .Range("F12").Value) / 3
Trim4 = (.Range("F5").Value + .Range("F9").Value + .Range("F13").Value) / 3
' prévisions brutes
prévisionBrut1 = .Range("H4").Value * .Range("H24").Value + .Range("H5").Value
prévisionBrut2 = .Range("H4").Value * .Range("H25").Value + .Range("H5").Value
prévisionBrut3 = .Range("H4").Value * .Range("H26").Value + .Range("H5").Value
prévisionBrut4 = .Range("H4").Value * .Range("H27").Value + .Range("H5").Value
' prévisions saisonnalisées
prévisionSaiso1 = prévisionBrut1 * Trim1
prévisionSaiso2 = prévisionBrut2 * Trim2
prévisionSaiso3 = prévisionBrut3 * Trim3
prévisionSaiso4 = prévisionBrut4 * Trim4
' affichage des autres résultats
.Cells(18, 8).Value = Trim1
.Cells(19, 8).Value = Trim2
.Cells(20, 8).Value = Trim3
.Cells(21, 8).Value = Trim4
.Cells(24, 9).Value = prévisionBrut1
.Cells(25, 9).Value = prévisionBrut2
.Cells(26, 9).Value = prévisionBrut3
.Cells(27, 9).Value = prévisionBrut4
.Cells(24, 10).Value = prévisionSaiso1
.Cells(25, 10).Value = prévisionSaiso2
.Cells(26, 10).Value = prévisionSaiso3
.Cells(27, 10).Value = prévisionSaiso4
End With
End Sub |
Partager