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
| Option Explicit
Sub test()
Dim Ws2 As Worksheet
Dim i As Integer, ModeCalcul As XlCalculation
Dim Nbligne As Long
Set Ws2 = Worksheets("Feuil2")
With Worksheets("Feuil1")
.Range("A7:A100").Clear
ModeCalcul = Application.Calculation
'Teste de cellule non vide sur la colonne B
.Range("A6").FormulaR1C1 = "=100-COUNTBLANK(R[100]C[1]:R[1]C[1])"
Nbligne = .Range("A6")
'La variable x va successivement prendre les valeurs 3 à Derncellule vide
For i = 7 To Nbligne + 6
'Ecrit dans la plage de cellules A....
If .Cells(i, 6) = "D" And Format(Date, "# ##0") >= Format(.Cells(i, 11), "# ##0") And Format(Date, "# ##0") <= Format(.Cells(i, 12), "# ##0") Then .Cells(i, 1) = "a " & Format(.Cells(i, 12), "# ##0") - Format(Date, "# ##0") & " jours"
If .Cells(i, 6) = "D" And Format(Date, "# ##0") >= Format(.Cells(i, 11), "# ##0") And Format(Date, "# ##0") >= Format(.Cells(i, 12), "# ##0") Then .Cells(i, 1) = "i " & Format(Date, "# ##0") - Format(.Cells(i, 12), "# ##0") & " jours"
If .Cells(i, 6) = "D" And Format(Date, "# ##0") < Format(.Cells(i, 11), "# ##0") Then .Cells(i, 1) = ""
If .Cells(i, 6) = "D" And .Cells(i, 11) = "0" Then .Cells(i, 1) = ""
'Formule
If .Cells(i, 6) = "C" Then
If Application.Vlookup(.Cells(i, 2), Ws2.Range("B3:E100"), 4, False) > .Cells(i, 11) And Application.Vlookup(.Cells(i, 2), Ws2.Range("B3:E100"), 4, False) < .Cells(i, 12) Then
.Cells(i, 1) = "a " & CStr(.Cells(i, 12) - Application.Vlookup(.Cells(i, 2), Ws2.Range("B3:E100"), 4, False)) & " heures"
End If
End If
Next i
End With
End Sub |
Partager