Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LOt As ListObject, L&, C%, CSurfac%, CelSurfac As Range, CPrixUn%, CelPrixUn As Range, _
CPrixAp%, CelPrixAp As Range
If Target.CountLarge > 1 Then Exit Sub
Set LOt = Me.ListObjects(1)
L = Target.Row - LOt.Range.Row: C = Target.Column - LOt.Range.Column + 1
If L < 1 Or L > LOt.ListRows.Count + 1 Then Exit Sub
CSurfac = LOt.ListColumns("SHAB").Index
Set CelSurfac = LOt.DataBodyRange(L, CSurfac)
CPrixUn = LOt.ListColumns("PRIX m² T.T.C").Index
Set CelPrixUn = LOt.DataBodyRange(L, CPrixUn)
CPrixAp = LOt.ListColumns("PRIX DE VENTE T.T.C " & vbLf & "(hors pkg)").Index
Set CelPrixAp = LOt.DataBodyRange(L, CPrixAp)
Application.EnableEvents = False
If C <> CPrixAp Then
CelPrixAp.Value = CCur(CelPrixUn.Value * CelSurfac.Value)
ElseIf CelSurfac.Value <> 0 Then
CelPrixUn.Value = CCur(CelPrixAp.Value / CelSurfac.Value)
Else
If CelPrixUn.Value = 0 Then CelPrixUn.Value = CCur(WorksheetFunction _
.Average(LOt.ListRows(CPrixUn).DataBodyRange.Value))
CelSurfac.Value = CDbl(CelPrixAp.Value / CelPrixUn.Value)
End If
Application.EnableEvents = True
End Sub