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
| Sub revalorisation()
Call effacer_donnees_revalorisation
'Declaration
Dim i As Integer
Dim nbLigne As Integer
Dim nb_annee_dev As Integer
'affectation
nb_annee_dev = 11
i = 6
While Feuil3.Cells(i, 3) <> ""
i = i + 1
Wend
nbLigne = i - 1
'Copy de la page Sinistres (données) a la page revalorisation
Sheets("Sinistres").Range("C6:F" & nbLigne).Copy Destination:=Sheets("Revalorisation des sinistres").Range("C6")
Dim TAB_Coef(), TAB_Sinistre(), TAB_Final()
Dim DIC_1, DIC_2, DIC_3, DIC_4, DIC_5
Dim annee_Cotation As Double
annee_Cotation = Worksheets("Sinistres").Range("D4").Value
'*********Dictionaire pour tes coefs **********'
Set DIC_1 = CreateObject("Scripting.Dictionary")
Set DIC_2 = CreateObject("Scripting.Dictionary")
Set DIC_3 = CreateObject("Scripting.Dictionary")
Set DIC_4 = CreateObject("Scripting.Dictionary")
Set DIC_5 = CreateObject("Scripting.Dictionary")
'*********Capture de tes deux tableaux dans des variables TAB_Coef et TAB_Sinistre **********'
Sheets("Coefficient de revalorisation").Activate
With ActiveWorkbook.ActiveSheet
lr = Cells(Rows.Count, 3).End(xlUp).Row
lc = Cells(7, Columns.Count).End(xlToLeft).Column
TAB_Coef = .Range(.Cells(7, 3), .Cells(lr, lc)).Value
End With
Sheets("Sinistres").Select
With ActiveWorkbook.ActiveSheet
lr = Cells(Rows.Count, 3).End(xlUp).Row
lc = Cells(6, Columns.Count).End(xlToLeft).Column
ReDim TAB_Final(1 To lr, 1 To lc)
TAB_Sinistre = .Range(.Cells(6, 4), .Cells(lr, lc)).Value
End With
'*********Ajout des coefs avec l'année en clé et le coeficient associé **********'
For i = 1 To UBound(TAB_Coef)
DIC_1.Add TAB_Coef(i, 1), TAB_Coef(i, 2)
DIC_2.Add TAB_Coef(i, 1), TAB_Coef(i, 3)
DIC_3.Add TAB_Coef(i, 1), TAB_Coef(i, 4)
DIC_4.Add TAB_Coef(i, 1), TAB_Coef(i, 5)
DIC_5.Add TAB_Coef(i, 1), TAB_Coef(i, 6)
Next i
'*********Boucle dans ton tableau de sinistre pour multiplier les valeurs en fonction du coeficient **********'
For i = 1 To UBound(TAB_Sinistre, 1)
For j = 4 To UBound(TAB_Sinistre, 2)
If TAB_Sinistre(i, j) <> "" And TAB_Sinistre(i, 3) = "Réglés" Then
Select Case TAB_Sinistre(i, j)
Case Is < 1000000
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_1(annee_Cotation) / DIC_1(TAB_Sinistre(i, 1))
Case Is < 2000000
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_2(annee_Cotation) / DIC_2(TAB_Sinistre(i, 1))
Case Is < 3000000
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_3(annee_Cotation) / DIC_3(TAB_Sinistre(i, 1))
Case Is < 4000000
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_4(annee_Cotation) / DIC_4(TAB_Sinistre(i, 1))
Case Else
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_5(annee_Cotation) / DIC_5(TAB_Sinistre(i, 1))
End Select
ElseIf TAB_Sinistre(i, j) <> "" And TAB_Sinistre(i, 3) = "Suspens" Then
Select Case TAB_Sinistre(i, j)
Case Is < 1000000
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_1(annee_Cotation + j - 4) / DIC_1(TAB_Sinistre(i, 1) + j - 4)
Case Is < 2000000
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_2(annee_Cotation + j - 4) / DIC_2(TAB_Sinistre(i, 1) + j - 4)
Case Is < 3000000
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_3(annee_Cotation + j - 4) / DIC_3(TAB_Sinistre(i, 1) + j - 4)
Case Is < 4000000
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_4(annee_Cotation + j - 4) / DIC_4(TAB_Sinistre(i, 1) + j - 4)
Case Else
TAB_Sinistre(i, j) = TAB_Sinistre(i, j) * DIC_5(annee_Cotation + j - 4) / DIC_5(TAB_Sinistre(i, 1) + j - 4)
End Select
ElseIf TAB_Sinistre(i, j) <> "" And TAB_Sinistre(i, 3) = "Total" Then
TAB_Sinistre(i, j) = TAB_Sinistre(i - 2, j) + TAB_Sinistre(i - 1, j)
End If
Next j
Next i
'*********Création d'un TAB_Final pour ne Resize que les données modifiées **********
For i = 1 To UBound(TAB_Sinistre, 1)
For j = 4 To UBound(TAB_Sinistre, 2)
TAB_Final(i, j - 3) = TAB_Sinistre(i, j)
Next j
Next i
Sheets("Revalorisation des sinistres").Select
With ActiveWorkbook.ActiveSheet
.Range(.Cells(6, 7), .Cells(lr, lc)).Value = TAB_Final
End With
End Sub |