Bonjour,
Testes avec ce code mais il va falloir adapter car je ne me suis pas trop creusé pour tout comprendre :
Private Sub BtValider_Click()
Dim Plage As Range
Dim Cel As Range
Dim I As Long
Worksheets("Devis").Select
If TextBox9.Value = "" Then
MsgBox "La Quantité ne peut pas être vide, veuillez compléter", vbCritical, "Invalide"
Exit Sub
End If
With Worksheets("Devis"): Set Plage = .Range(.Cells(2, 2), .Cells(.Rows.Count, 2).End(xlUp)): End With
Set Cel = Plage.Find(Textbox1.Text, , xlValues, xlWhole)
If Cel Is Nothing Then
I = Plage.Rows.Count + 2
Else
If MsgBox("Cet Ouvrage existe Déjà." & Chr(13) & "Remplacer ?", _
vbYesNo + vbInformation, _
"Information !") = vbYes Then I = Cel.Row Else I = Plage.Rows.Count + 2
End If
'vraiment nécessaire ?
' MsgBox "Cet Ouvrage ne figure pas au Devis !" & Chr(13) & _
' "Ajouter au Devis ?", vbOKOnly + vbQuestion, "Information !"
With Worksheets("Devis")
.Cells(I, 2).Value = Textbox1.Text 'Code
.Cells(I, 4).Value = Textbox2.Text 'Désignation
.Cells(I, 5).Value = Textbox3.Text 'Unité
.Cells(I, 6).Value = TextBox9.Text 'Quantité
.Cells(I, 7).Value = TextBox6.Text 'Matériaux
.Cells(I, 8).Value = 0 ' <--- Total fourniture ? Adapter !!!
.Cells(I, 9).Value = TextBox5.Text 'M.O
.Cells(I, 10).Value = 0 ' <--- Total main d'oeuvre !!!
.Cells(I, 11).Value = 0 ' <--- Main d'oeuvre Prix de revient !!!
.Cells(I, 12).Value = CDbl(TextBox7.Text) 'Main d'oeuvre + fourniture Prix de revient
.Cells(I, 13).Value = 0 ' <--- Prix unitaire Prix de vente !!!
.Cells(I, 14).Value = CDbl(TextBox8.Text) 'Montant Prix de vente
End With
Textbox1.Value = ""
Textbox2.Value = ""
Textbox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
'PrixUnitaire
'ActiveWorkbook.Sheets("Base_de_prix").Select
End Sub
Dans le bloc ci-dessous, il t'es assez facile d'adapter les TextBox aux colonnes car elles se suivent :
.Cells(I, 2).Value = Textbox1.Text 'Code
.Cells(I, 4).Value = Textbox2.Text 'Désignation
.Cells(I, 5).Value = Textbox3.Text 'Unité
.Cells(I, 6).Value = TextBox9.Text 'Quantité
.Cells(I, 7).Value = TextBox6.Text 'Matériaux
.Cells(I, 8).Value = 0 ' <--- Total fourniture ? Adapter !!!
.Cells(I, 9).Value = TextBox5.Text 'M.O
.Cells(I, 10).Value = 0 ' <--- Total main d'oeuvre
.Cells(I, 11).Value = 0 ' <--- Main d'oeuvre Prix de revient
.Cells(I, 12).Value = CDbl(TextBox7.Text) 'Main d'oeuvre + fourniture Prix de revient
.Cells(I, 13).Value = 0 ' <--- Prix unitaire Prix de vente
.Cells(I, 14).Value = CDbl(TextBox8.Text) 'Montant Prix de vente