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
| Option Explicit
' Sheet source
Const indSheetSource = 2
Const rowSrcStart = 2
Const rowSrcEnd = 52
Const colSrcOk = 12
Const colSrcMax = 15
' Sheet target
Const indSheetTarget = 3
Const colLastYear = 228
Const formulaIf1 = "=IF(AND(YEAR(DATE(YEAR(DATA!RC10),month(DATA!RC10)+(12*"
Const formulaIf2 = "),day(DATA!RC10)))=YEAR(R1C),MONTH(DATE(year(DATA!RC10),month(DATA!RC10)+(12*"
Const formulaIf3 = "),day(DATA!RC10)))=month(R1C)),DATA!RC8*DATA!RC7/100,0)*(VLOOKUP(DATA!RC6,'CRCY'!R1C1:R14C3,3,0))"
Sub SetFormulaYear()
Dim indRow As Integer, indColSrc As Integer, indColEnd As Integer, indColYear As Integer
Dim strFormula As String, strPrm As String
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For indRow = rowSrcStart To rowSrcEnd ' ligne
If Sheets(indSheetSource).Cells(indRow, colSrcOk) = "OK" Then
indColEnd = Sheets(indSheetSource).Cells(indRow, colSrcMax)
For indColSrc = 1 To indColEnd
For indColYear = 1 To colLastYear ' colonne
With Worksheets(indSheetTarget)
If .Cells(indRow, indColYear) = 0 Then
strPrm = CStr(indColSrc - 1)
strFormula = formulaIf1 + strPrm + formulaIf2 + strPrm + formulaIf3
.Cells(indRow, indColYear).FormulaR1C1 = strFormula
End If
End With
Next
Next
End If
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub |
Partager