Bonjour,
Une proposition à étudier.
Cdlt.
Public Sub InsertRowInTable()
Dim lo As ListObject
Dim LR As ListRow
Dim n As Long
Dim sValue As String
If ActiveCell.ListObject Is Nothing Then
MsgBox "Vous devez sélectionner une cellule du tableau.", _
vbInformation, "Insertion ligne"
Exit Sub
Else
Set lo = ActiveCell.ListObject
n = ActiveCell.Row - lo.HeaderRowRange.Row
If n = 0 Then
MsgBox "La cellule sélectionnée doit être dans la plage des valeurs du tableau.", _
vbInformation, "Insertion ligne"
GoTo exit_Handler
End If
sValue = lo.ListRows(n).Range.Cells(1, 2)
Set LR = lo.ListRows.Add(n)
With LR.Range
.Cells(1, 1).Value = WorksheetFunction.Max(lo.ListColumns(1).DataBodyRange) + 1
.Cells(1, 2).Value = sValue
End With
End If
Set LR = Nothing
exit_Handler:
Set lo = Nothing
End Sub