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
' ajout des données concernant le vin Zone Jaune du tableau colonne 1 à 7
.Cells(MyLastRow, 1) = CBB2.Value & " " & CBB3.Value & " " & CBB4.Value & " " & CBB6 ' Appellation + classement + climat + année
.Cells(MyLastRow, 2) = CBB1.Value ' Région
.Cells(MyLastRow, 3) = CBB5.Value ' Couleur
.Cells(MyLastRow, 4) = CBB7.Value ' Nbre achat
.Cells(MyLastRow, 5) = CBB11.Value ' Contenance
.Cells(MyLastRow, 6) = CBB6.Value ' Millesime
.Cells(MyLastRow, 7) = CBB9.Value & "." & CBB10.Value ' Rangement
.Cells(MyLastRow, 18) = CBB8.Value ' Région
' ajout des données concernant le domaine Zone rose du tableau colonne 8 à 12
.Cells(MyLastRow, 8) = TxtDomaine.Value ' Nom du domaine
.Cells(MyLastRow, 9) = TxtAdresse & " " & TxtCp.Value & " " & TxtVille.Value ' adresse
.Cells(MyLastRow, 10) = TxtTel.Value 'Telephone
.Cells(MyLastRow, 11) = TxtMail.Value ' Mail
.Cells(MyLastRow, 12) = TxtInternet.Value ' internet
' ajout des donnees concernant les caracteristiques du vin
.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
'Classement des vins par annee
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