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
| Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Dim v As Double
Dim f As String
Dim DernLigne As Long
DernLigne = Range("B1048576").End(xlUp).Row
If Intersect(Target, Range("B11:B" & DernLigne)) Is Nothing Then Exit Sub
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For Each c In Target.Cells
If c.Column = 2 Then
f = c.NumberFormatLocal
c.NumberFormatLocal = "Standard"
v = Val(c.Formula)
On Error Resume Next
If Not IsDate(c.Text) Then If v >= 1011900 And v <= 31129999 And Int(v) = v Then c.Value = CDate(Format(v, "00\/00\/0000"))
On Error GoTo 0
If IsDate(c.Text) Then c.NumberFormatLocal = "jj/mm/aaaa" Else c.NumberFormatLocal = f
End If
If c.Column = 2 Then
c.Offset(0, 5).FormulaR1C1 = "=R[-1]C-RC[-2]+RC[-1]"
c.Offset(0, 6).FormulaR1C1 = "=round(R[-1]C+if(RC[-7]=""X"",1,0)*(-RC[-3]+RC[-2]),2)"
c.Offset(0, 8).FormulaR1C1 = "=IF(MONTH(RC[-8]) = MONTH(TODAY()), IF(YEAR(RC[-8])=YEAR(TODAY()),IF(DAY(RC[-8])>=DAY(R[-1]C[-8]),DAY(RC[-8]),""""),""""),"""")"
c.Offset(0, 9).FormulaR1C1 = "=IF(RC[-1] <>"""",RC[-4],"""")"
End If
Next c
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub |
Partager