Private Sub CommandButton1_Click()
Dim MyLastRow As Integer
Dim UserAnswer As VbMsgBoxResult
Dim tbl As ListObject
Dim ws As Worksheet
Dim sortcolumn As Range
UserAnswer = MsgBox("• Confirmez-vous cet ajout?", vbYesNo + vbQuestion, "Confirmation!")
If CStr(UserAnswer) = CStr(False) Then Exit Sub
If UserAnswer = vbCancel Then Exit Sub
If UserAnswer = vbNo Then Exit Sub
Set ws = Application.ThisWorkbook.Worksheets("liste_vin")
With ws
.Activate
MyLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Cells(MyLastRow, 1) = CBB2.Value & " " & CBB3.Value & " " & CBB4.Value & " " & CBB6
.Cells(MyLastRow, 2) = CBB1.Value
.Cells(MyLastRow, 3) = CBB5.Value
.Cells(MyLastRow, 4) = CBB7.Value
.Cells(MyLastRow, 5) = CBB11.Value
.Cells(MyLastRow, 6) = CBB6.Value
.Cells(MyLastRow, 7) = CBB9.Value & "." & CBB10.Value
.Cells(MyLastRow, 18) = CBB8.Value
.Cells(MyLastRow, 8) = TxtDomaine.Value
.Cells(MyLastRow, 9) = TxtAdresse & " " & TxtCp.Value & " " & TxtVille.Value
.Cells(MyLastRow, 10) = TxtTel.Value
.Cells(MyLastRow, 11) = TxtMail.Value
.Cells(MyLastRow, 12) = TxtInternet.Value
.Cells(MyLastRow, 13) = TxtInformation.Value
.Cells(MyLastRow, 14) = TxtQuemangerAvec.Value
.Cells(MyLastRow, 15) = TxtCaracteristique.Value
.Cells(MyLastRow, 16) = TxtServiceVin.Value
.Cells(MyLastRow, 17) = TxtConservation.Value
End With
Set tbl = ws.ListObjects("Tableau2")
Set sortcolumn = Range("Tableau2[Millesime]")
With tbl.Sort
.SortFields.Clear
.SortFields.Add Key:=sortcolumn, SortOn:=xlSortOnValues, Order:=xlAscending
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
If Not sortcolumn Is Nothing Then Set sortcolumn = Nothing
If Not tbl Is Nothing Then Set tbl = Nothing
If Not ws Is Nothing Then Set ws = Nothing
End Sub