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
|
Option Explicit
'même principe de calcul
'la macro se déclenche dès qu'on modifie la valeur d'une cellule
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Tabl As Variant, C As Range, i As Long, Valid As Boolean
'si la cellule modifiée ("Target") n'est pas dans les colonnes A:F, arrêt de la macro
If Intersect(Target, [A:F]) Is Nothing Then Exit Sub
Application.EnableEvents = False
Application.ScreenUpdating = False
'si toutes les cellules de la ligne sont renseignées
If Application.WorksheetFunction.CountA(Range(Cells(Target.Row, 1), Cells(Target.Row, 6))) = 6 Then
'calcul du résultat pour la ligne (voir la macro "Calcul")
With Sheets("Feuil1")
Tabl = .Range(.[A2], .Cells(.Rows.Count, 13).End(xlUp))
End With
With Sheets("table AS_IS")
For Each C In Target
Valid = False
For i = 1 To UBound(Tabl, 1)
If .Cells(C.Row, 1) = Tabl(i, 1) And .Cells(C.Row, 2) = Tabl(i, 2) Then
If Left(.Cells(C.Row, 3), 2) >= Tabl(i, 3) And Left(.Cells(C.Row, 3), 2) <= Left(Tabl(i, 4), 2) Then
If .Cells(C.Row, 4) >= Tabl(i, 5) And .Cells(C.Row, 4) <= Tabl(i, 6) Then
If .Cells(C.Row, 5) >= Tabl(i, 7) And .Cells(C.Row, 5) <= Tabl(i, 8) Then
If .Cells(C.Row, 6) >= Tabl(i, 9) And .Cells(C.Row, 6) <= Tabl(i, 10) Then
.Cells(C.Row, 29) = Tabl(i, 11) * .Cells(C.Row, 5) + _
Tabl(i, 12) * .Cells(C.Row, 6)
Valid = True
Exit For
End If
End If
End If
End If
End If
Next i
If Not Valid Then .Cells(C.Row, 29) = "not in contract"
Next C
End With
End If
Application.EnableEvents = True
Application.EnableEvents = True
End Sub |
Partager