bonjour
J'ai essayé mais ça ne marche pas
Private Sub CmbAjouter_Click()
Dim Ligne, mois As Long
Dim jour As Integer
Dim Date1, Date2 As Date
With Ws
If Me.cbbmachine.ListIndex = -1 Then
If Trim(Me.cbbmachine) = "" Then
MsgBox "Le nom de la machine est obligatoire"
Else
If MsgBox("Voulez-vous ajouter un nouvel enregistrement ?", _
vbQuestion + vbYesNo, "Ajouter") <> vbYes Then Exit Sub
Ligne = .Range("A" & Rows.Count).End(xlUp).Row + 2
.Range("A6:E7").Copy .Range("A" & Ligne)
.Range("A" & Ligne).Resize(2, 5).ClearContents
.Range("A" & Ligne) = Me.cbbmachine
End If
Else
If MsgBox("Voulez-vous modifier cet enregistrement ?", _
vbQuestion + vbYesNo, "Modifier") <> vbYes Then Exit Sub
Ligne = (Me.cbbmachine.ListIndex * 2) + 6
End If
TextBox3 = ""
If Not (IsDate(TextBox4) Or IsDate(TextBox2)) Then
MsgBox "Format incorrect"
TextBox4 = ""
TextBox2 = ""
Exit Sub
Else
If TextBox2 = "" Then TextBox2 = Date
If CDate(TextBox2) <= CDate(TextBox4) Then
MsgBox "Attention! Date 2 inférieure ou égale à date 1", vbExclamation
Exit Sub
End If
Date1 = Format(TextBox4, "mm/dd/yyyy")
Date2 = Format(TextBox2, "mm/dd/yyyy")
jour = Evaluate("DATEDIF(""" & Date1 & """,""" & Date2 & """,""md"")")
mois = Evaluate("DATEDIF(""" & Date1 & """,""" & Date2 & """,""m"")")
TextBox3 = mois & " mois et " & jour & " jour(s)"
End If
.Range("F" & Ligne) = Me.TextBox2
.Range("C" & Ligne) = Me.TbxMoteur
.Range("G" & Ligne) = Me.TextBox3.Value
.Range("F" & Ligne + 1) = Me.TextBox4.Value
End With
InitCbb
End Sub
merci de votre aide