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
| Sub Update_Data_Date()
Dim Baseline As Worksheet
Dim Trment As Worksheet
Dim Bsl As Range
Dim TR As Range
Dim MyTab() As String
Dim MTab As Integer
Dim LastCol As Integer
Dim NbLine As Integer
Dim NbFile As Integer
Dim DeCol As Integer
Dim i As Integer
Dim j As Integer
Dim x As Integer
Set Baseline = ThisWorkbook.Sheets("Baseline")
Set Trment = ThisWorkbook.Sheets("Treatment")
Set TR = Trment.Range("A1")
Set Bsl = Baseline.Range("A1")
With Sheets("Baseline")
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column ' On compte le nombre de colonne de l'onglet Baseline
End With
With Sheets("Baseline")
NbLine = .Cells(.Rows.Count, 1).End(xlUp).Row - 1 ' On compte le nombre de ligne
End With
NbFile = NbLine / 5
ReDim MyTab(0 To NbLine, 0 To LastCol)
For i = 0 To UBound(MyTab, 1) Step 5
MyTab(i, j) = Bsl.Offset(i, j)
TR.Offset(i + 1, 2) = Month(MyTab(i, j)) & "-" & "01" & "-" & Year(MyTab(i, j)) 'Ici on met la date de la première cellulle
TR.Offset(i + 1, 2).NumberFormat = "[$-410]dd-mmm-yy;@"
TR.Offset(i + 1, 5).FormulaR1C1 = "=R[0]C[-3]-R1C3" ' Ici on met en cellule F"i+1" la formule : =C"i+1" -C$1$ pour calculer le nb de jour entre la date de
' la première cellule et la date la plus ancienne de la feuille
Next i
TR.Offset(0, 2).FormulaR1C1 = "=MIN(R[1]C:R[" & NbLine - 3 & "]C)" 'Ici on met en cellule C1 la formule pour trouver la date la plus ancienne = MIN (C2:C"NbLine -3")
TR.Offset(0, 2).NumberFormat = "0000"
i = 0
j = 0
Do While Bsl.Offset(i, 0) <> ""
DeCol = Int(TR.Offset(i + 1, 5) / 30) ' Ici on calcule le rapport entre Nb de jour pour décaler le nb de colonne nécessaire(ex si en F2 on a 91 DeCol sera égal à 3, on décalera de 3 Colonne)
If Bsl.Offset(i, j) <> Bsl.Offset(i + 5, j) And DeCol <> 0 Then
Range(Bsl.Offset(i, j), Bsl.Offset(i + 4, j + DeCol - 1)).Insert Shift:=xlToRight ' Ici on décale du nb de cellule nécessaire
Set Bsl = Baseline.Range("A1")
For j = 0 To DeCol - 1
Bsl.Offset(i, j).Select
If Bsl.Offset(i, 0) = "" Then
MTab = Month(TR.Range("C1"))
Else
MTab = Month(Bsl.Offset(i, j - 1))
End If
If MTab = 4 Or MTab = 6 Or MTab = 9 Or MTab = 11 Then
x = 30
ElseIf MTab = 2 Then
x = 28
Else
x = 31
End If
If j = 0 Then
Bsl.Offset(i, j) = TR.Range("C1")
Else
Bsl.Offset(i, j) = Bsl.Offset(i, j - 1) + x
End If
Bsl.Offset(i, j).NumberFormat = "[$-410]mmm-yy;@"
Bsl.Offset(i + 1, j) = 0
Bsl.Offset(i + 1, j).NumberFormat = "0.00%"
Bsl.Offset(i + 2, j) = 0
Bsl.Offset(i + 2, j).NumberFormat = "0.00%"
Bsl.Offset(i + 3, j) = 0
Bsl.Offset(i + 3, j).NumberFormat = " 0.00"
Bsl.Offset(i + 4, j) = 0
Bsl.Offset(i + 4, j).NumberFormat = " 0.00"
Next j
End If
i = i + 5
j = 0
Loop
End Sub |