Re : numéro de facture automatique
Hello,
Voici une solution à placer dans le code vba de ta feuille :
Il se déclenche à partir de la ligne 3
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A:A")) Is Nothing Then
If Application.Intersect(Target, Range("a1:a2")) Is Nothing Then
If ActiveCell.Column = 1 Then
If Cells(ActiveCell.Row - 2, 1) = "" Or Cells(ActiveCell.Row - 2, 6) = "" Then
MsgBox "la ligne précédente n'est pas totalement renseignée"
Exit Sub
End If
If Cells(ActiveCell.Row - 1, 6) <> "" Then
reponse = MsgBox("Attention le N° de facture est déjà renseigné voulez vous l'écraser ?", vbYesNo)
If reponse = vbNo Then Exit Sub
End If
Cells(ActiveCell.Row - 2, 6).Select
Selection.AutoFill Destination:=Range(Cells(ActiveCell.Row, 6), Cells(ActiveCell.Row + 1, 6)), Type:=xlFillDefault
Cells(ActiveCell.Row + 2, 1).Select
End If
If ActiveCell.Column = 2 Then
If Cells(ActiveCell.Row - 1, 1) = "" Or Cells(ActiveCell.Row - 1, 6) = "" Then
MsgBox "la ligne précédente n'est pas totalement renseignée"
Exit Sub
End If
If Cells(ActiveCell.Row, 6).Value <> "" Then
reponse = MsgBox("Attention le N° de facture est déjà renseigné voulez vous l'écraser ?", vbYesNo)
If reponse = vbNo Then Exit Sub
End If
Cells(ActiveCell.Row - 1, 6).Select
Selection.AutoFill Destination:=Range(Cells(ActiveCell.Row, 6), Cells(ActiveCell.Row + 1, 6)), Type:=xlFillDefault
Cells(ActiveCell.Row + 1, 1).Select
End If
End If
End If
End Sub