Option Explicit
Private Sub Save_Data()
Dim lo As ListObject
Dim lr As ListRow
Dim n As Long
Dim d
n = Application.Count([B1:B2])
If n < 2 Then
MsgBox "La date et le n° de référence doivent être documentés"
Exit Sub
End If
Set lo = Worksheets("HISTO").ListObjects(1)
n = lo.ListRows.Count
Select Case True
Case [B1].Value > n
Set lr = lo.ListRows.Add
Case Else
d = Application.Match([B1].Value, lo.ListColumns(1).DataBodyRange, 0)
If IsError(d) Then
MsgBox "La référence est inconnue..."
Exit Sub
Else
Set lr = lo.ListRows(d)
End If
End Select
With lr.Range
.Cells(1, 1).Value = [B1]
.Cells(1, 2).Value = [B2]
.Cells(1, 5).Value = [B5]
.Cells(1, 6).Value = [B6]
.Cells(1, 7).Value = [B7]
.Cells(1, 8).Value = [B8]
End With
[B1:B2,B5:B8].ClearContents
With Worksheets("HISTO")
.Activate
.[A1].Select
End With
Set lo = Nothing
End Sub