Private Sub Valider_Click()
ActiveSheet.Unprotect
' Champs obligatoires
If Client.Text = "" Then
MsgBox "Le champs Client n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
If Modeles.Text = "" Then
MsgBox "Le champs Modeles n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
If Qui_Initiales.Text = "" Then
MsgBox "Le champs Défauts détectés n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
If Origine.Text = "" Then
MsgBox "Le champs Origine n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
'If Localisation.Text = "" Then
'MsgBox "Le champs Localisation du défaut n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
' Exit Sub
'End If
If N°OF.Text = "" Then
MsgBox "Le champs N°OF n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
If Qte.Text = "" Then
MsgBox "Le champs Qté initiale n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
If NC.Text = "" Then
MsgBox "Le champs Qté NC n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
If Defaut.Text = "" Then
MsgBox "Le champs Description du défaut n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
If Decision.Text = "" Then
MsgBox "Le champs décision retouche, déchets retour fournisseur n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
If N°OF.TextLength <> 15 Then
MsgBox "Le N°OF n'a pas été rempli correctement. Veuillez le remplir correctement.", vbOKOnly + vbInformation, "Champs incorrects"
Exit Sub
End If
'Cohérence quantité rentrée
If CInt(NC.Value) > CInt(Qte.Value) Then
MsgBox "La quantité NC est supérieure à la quantité initiale" & Chr(13) & "Veuiller les modifier et revalider", vbOKOnly + vbCritical, "Qté NC / OF incorrecte"
Exit Sub
End If
'Affectation des données dans la FA
With Sheets("FA")
.Cells(6, 2) = Qui
.Cells(6, 4).Value = Qui_Initiales
.Cells(6, 5).Value = Date
.Cells(24, 2).Value = Date
.Cells(7, 2).Value = Modeles
.Cells(7, 7).Value = Qte
.Cells(8, 2).Value = N°OF
.Cells(9, 2).Value = Client
.Cells(9, 7).Value = NC
.Cells(20, 2).Value = Origine
.Cells(16, 4).Value = Defaut
.Cells(12, 2).Value = Qui_Initiales
'.Cells(16, 1).Value = Commentaire
'.Cells(19, 1).Value = Decision
End With
'Affectation des données dans le listing
With Sheets("Synthese")
Date_D = Date
newRecord = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Cells(newRecord, 1) = Date_D
'Cells(newRecord, 2) = Semaine_D
.Cells(newRecord, 3) = Qui_Initiales
.Cells(newRecord, 4) = Qui
.Cells(newRecord, 5) = Origine
'Cells(newRecord, 5) = Localisation.Text
.Cells(newRecord, 6) = Modeles.Text
'Cells(newRecord, 7) = Coloris.Text
.Cells(newRecord, 7) = Client.Text
.Cells(newRecord, 8) = N°OF.Text
.Cells(newRecord, 9) = Qte.Text
.Cells(newRecord, 10) = NC.Text
If Val(NC.Text) <> 0 Then .Cells(newRecord, 11) = Val(NC.Text) / Val(Qte.Text)
.Cells(newRecord, 12) = Defaut.Text
.Cells(newRecord, 13) = Commentaire.Text
.Cells(newRecord, 14) = Decision.Text
'Cells(newRecord, 15) = resp_retouche.Text
'Cells(newRecord, 16) = temps_retouche.Text
'Cells(newRecord, 19) = Origine_defaut
End With
AffichFA = False
If Val(NC.Text) / Val(Qte.Text) * 100 >= 80 Then
AffichFA = True
ElseIf MsgBox("Voulez vous imprimer une FA?", vbYesNo) = vbYes Then
AffichFA = True
End If
If AffichFA = True Then
UserForm1.Hide
Worksheets("FA").PrintPreview
End If
'Suppression des données changeantes à chaque nouvelles saisies
'Origine.Text = ""
'N°OF.Text = ""
'Qte.Text = ""
NC.Text = ""
'Defaut.Text = ""
Commentaire.Text = ""
'Ne ferme pas l'UserForm mais le masque.
UserForm1.Hide
ActiveSheet.Protect
End Sub