Formulaire Textbox date
Bonjour, je suis toutes novice avec VBA. J'ai voulu créer un formulaire sauf que je ne sais pas comment faire pour les dates sur mes textbox ma feuille de calcul ne reconnait pas les dates .
Pourriez-vous m'aider ?
Bonjour,
range("A1") = CDate(textbox1) > convertir une date format texte en date format date ...
Note : il y a de beaux tutos "Gratuits" ici : https://www.excel-pratique.com/fr/vba
ric
Bonjour,
je ne comprend pas il m'indique une erreur d'execussion 13
Pouvez-vous m'aider ? Ci-joint mon code formulaire
Private Sub ComboBox12_AfterUpdate()
Set ws = Sheets("Base")
Dim ligne As Long
If Me.ComboBox12.ListIndex = -1 Then Exit Sub
ligne = Me.ComboBox12.ListIndex + 2
ComboBox12 = ws.Cells(ligne, "A")
TextBox3 = ws.Cells(ligne, "B")
ComboBox1 = ws.Cells(ligne, "C")
TextBox5 = ws.Cells(ligne, "D")
ComboBox25 = ws.Cells(ligne, "E")
ComboBox26 = ws.Cells(ligne, "F")
TextBox21 = ws.Cells(ligne, "G")
TextBox22 = ws.Cells(ligne, "H")
TextBox23 = ws.Cells(ligne, "I")
TextBox24 = ws.Cells(ligne, "J")
TextBox25 = ws.Cells(ligne, "K")
TextBox13 = ws.Cells(ligne, "L")
ComboBox3 = ws.Cells(ligne, "M")
TextBox16 = ws.Cells(ligne, "N")
TextBox7 = ws.Cells(ligne, "O")
ComboBox19 = ws.Cells(ligne, "P")
ComboBox22 = ws.Cells(ligne, "Q")
ComboBox21 = ws.Cells(ligne, "R")
CheckBox42 = ws.Cells(ligne, "S")
CheckBox43 = ws.Cells(ligne, "T")
CheckBox44 = ws.Cells(ligne, "U")
CheckBox45 = ws.Cells(ligne, "V")
CheckBox46 = ws.Cells(ligne, "W")
CheckBox47 = ws.Cells(ligne, "X")
CheckBox48 = ws.Cells(ligne, "Y")
CheckBox49 = ws.Cells(ligne, "Z")
CheckBox50 = ws.Cells(ligne, "AA")
TextBox17 = ws.Cells(ligne, "AB")
CheckBox52 = ws.Cells(ligne, "AC")
CheckBox53 = ws.Cells(ligne, "AD")
CheckBox54 = ws.Cells(ligne, "AE")
CheckBox55 = ws.Cells(ligne, "AF")
CheckBox56 = ws.Cells(ligne, "AG")
CheckBox57 = ws.Cells(ligne, "AH")
TextBox18 = ws.Cells(ligne, "AI")
CheckBox59 = ws.Cells(ligne, "AJ")
CheckBox60 = ws.Cells(ligne, "AK")
CheckBox61 = ws.Cells(ligne, "AL")
CheckBox62 = ws.Cells(ligne, "AM")
CheckBox63 = ws.Cells(ligne, "AN")
TextBox10 = ws.Cells(ligne, "AO")
CheckBox64 = ws.Cells(ligne, "AP")
CheckBox65 = ws.Cells(ligne, "AQ")
CheckBox66 = ws.Cells(ligne, "AR")
CheckBox67 = ws.Cells(ligne, "AS")
CheckBox68 = ws.Cells(ligne, "AT")
CheckBox69 = ws.Cells(ligne, "AU")
CheckBox70 = ws.Cells(ligne, "AV")
CheckBox71 = ws.Cells(ligne, "AW")
CheckBox72 = ws.Cells(ligne, "AX")
TextBox11 = ws.Cells(ligne, "AY")
ComboBox16 = ws.Cells(ligne, "AZ")
ComboBox15 = ws.Cells(ligne, "BA")
TextBox14 = ws.Cells(ligne, "BB")
ComboBox16 = ws.Cells(ligne, "BC")
ComboBox17 = ws.Cells(ligne, "BD")
ComboBox18 = ws.Cells(ligne, "BE")
TextBox20 = ws.Cells(ligne, "BF")
CheckBox73 = ws.Cells(ligne, "BG")
CheckBox74 = ws.Cells(ligne, "BH")
CheckBox75 = ws.Cells(ligne, "BI")
CheckBox76 = ws.Cells(ligne, "BJ")
CheckBox77 = ws.Cells(ligne, "BK")
CheckBox78 = ws.Cells(ligne, "BL")
TextBox19 = ws.Cells(ligne, "BM")
CheckBox80 = ws.Cells(ligne, "BN")
CheckBox81 = ws.Cells(ligne, "BO")
CheckBox82 = ws.Cells(ligne, "BP")
CheckBox83 = ws.Cells(ligne, "BQ")
CheckBox84 = ws.Cells(ligne, "BR")
TextBox12 = ws.Cells(ligne, "Bs")
End Sub
Private Sub TextBox13_AfterUpdate()
'Date sortie
On Error GoTo messagerreur
TextBox13 = Format(TextBox13, "Short date")
Exit Sub
messagerreur:
MsgBox ("Le format introduit n’est pas valide, le format de date est Jour/Mois/Année !")
TextBox13 = Empty
End Sub
Private Sub TextBox13_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii > 46 And KeyAscii < 58)) Then
KeyAscii = 0
End If
End Sub
Private Sub TextBox21_AfterUpdate()
'Date prolong1
On Error GoTo messagerreur
TextBox21 = Format(TextBox21, "Short date")
Exit Sub
messagerreur:
MsgBox ("Le format introduit n’est pas valide, le format de date est Jour/Mois/Année !")
TextBox21 = Empty
End Sub
Private Sub TextBox21_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii > 46 And KeyAscii < 58)) Then
KeyAscii = 0
End If
End Sub
Private Sub TextBox22_AfterUpdate()
'Date prolong2
On Error GoTo messagerreur
TextBox22 = Format(TextBox22, "Short date")
Exit Sub
messagerreur:
MsgBox ("Le format introduit n’est pas valide, le format de date est Jour/Mois/Année !")
TextBox22 = Empty
End Sub
Private Sub TextBox22_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii > 46 And KeyAscii < 58)) Then
KeyAscii = 0
End If
End Sub
Private Sub TextBox23_AfterUpdate()
On Error GoTo messagerreur
TextBox23 = Format(TextBox23, "Short date")
Exit Sub
messagerreur:
MsgBox ("Le format introduit n’est pas valide, le format de date est Jour/Mois/Année !")
TextBox23 = Empty
End Sub
Private Sub TextBox23_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii > 46 And KeyAscii < 58)) Then
KeyAscii = 0
End If
End Sub
Private Sub TextBox24_AfterUpdate()
'Date prolong4
On Error GoTo messagerreur
TextBox24 = Format(TextBox24, "Short date")
Exit Sub
messagerreur:
MsgBox ("Le format introduit n’est pas valide, le format de date est Jour/Mois/Année !")
TextBox24 = Empty
End Sub
Private Sub TextBox24_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii > 46 And KeyAscii < 58)) Then
KeyAscii = 0
End If
End Sub
Private Sub TextBox25_AfterUpdate()
'Date prolong5
On Error GoTo messagerreur
TextBox25 = Format(TextBox25, "Short date")
Exit Sub
messagerreur:
MsgBox ("Le format introduit n’est pas valide, le format de date est Jour/Mois/Année !")
TextBox25 = Empty
End Sub
Private Sub TextBox25_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii > 46 And KeyAscii < 58)) Then
KeyAscii = 0
End If
End Sub
Private Sub TextBox5_AfterUpdate()
On Error GoTo messagerreur
TextBox5 = Format(CDate(TextBox5), "dd-mm-yy")
Exit Sub
messagerreur:
MsgBox ("Le format introduit n’est pas valide, le format de date est Jour/Mois/Année !")
TextBox5 = Empty
End Sub
Private Sub TextBox5_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii > 46 And KeyAscii < 58)) Then
KeyAscii = 0
End If
End Sub
Private Sub UserForm_Initialize()
'Genre
Me.ComboBox1.ColumnCount = 1
ComboBox1.List() = Array("M", "F", "Autres")
'combobox alimentée par une feuille excel
Set ws = Sheets("Base")
With Me.ComboBox12
For J = 2 To ws.Range("A" & Rows.Count).End(xlUp).Row
.AddItem ws.Range("A" & J)
Next J
End With
End Sub
Private Sub CommandButton1_Click()
'code permettant de fermet la fênetre en vidant son contenu
Unload Me
End Sub
Private Sub CommandButton2_Click() 'Bouton Ajouter
'message de confirmation
If MsgBox("Conffirmez-vous la création de ce nouvel ajout ?", vbYesNo, "Demande de vonfirmation d'ajout") = vbYes Then
'mise à jour de la base de données
With Sheets("Base").Select
Dim L As Integer
L = Sheets("Base").Range("a65536").End(xlUp).Row + 1
Range("A" & L).Value = ComboBox12.Value
Range("B" & L).Value = TextBox3.Value
Range("C" & L).Value = ComboBox1.Value
Range("D" & L).Value = Format(CDate(TextBox5.Value), "dd-mm-yy")
Range("E" & L).Value = ComboBox25.Value
Range("F" & L).Value = ComboBox26.Value
Range("G" & L).Value = Format(CDate(TextBox21.Value), "dd-mm-yy")
Range("H" & L).Value = Format(CDate(TextBox22.Value), "dd-mm-yy")
Range("I" & L).Value = Format(CDate(TextBox23.Value), "dd-mm-yy")
Range("J" & L).Value = Format(CDate(TextBox24.Value), "dd-mm-yy")
Range("K" & L).Value = Format(CDate(TextBox25.Value), "dd-mm-yy")
Range("L" & L).Value = Format(CDate(TextBox13.Value), "dd-mm-yy")
Range("M" & L).Value = ComboBox3.Value
Range("N" & L).Value = TextBox16.Value
Range("O" & L).Value = TextBox7.Value
Range("P" & L).Value = ComboBox19.Value
Range("Q" & L).Value = ComboBox22.Value
Range("R" & L).Value = ComboBox21.Value
Range("S" & L).Value = CheckBox42.Value
Range("T" & L).Value = CheckBox43.Value
Range("U" & L).Value = CheckBox44.Value
Range("V" & L).Value = CheckBox45.Value
Range("W" & L).Value = CheckBox46.Value
Range("X" & L).Value = CheckBox47.Value
Range("Y" & L).Value = CheckBox48.Value
Range("Z" & L).Value = CheckBox49.Value
Range("AA" & L).Value = CheckBox50.Value
Range("AB" & L).Value = TextBox17.Value
Range("AC" & L).Value = CheckBox52.Value
Range("AD" & L).Value = CheckBox53.Value
Range("AE" & L).Value = CheckBox54.Value
Range("AF" & L).Value = CheckBox55.Value
Range("AG" & L).Value = CheckBox56.Value
Range("AH" & L).Value = CheckBox57.Value
Range("AI" & L).Value = TextBox18.Value
Range("AJ" & L).Value = CheckBox59.Value
Range("AK" & L).Value = CheckBox60.Value
Range("AL" & L).Value = CheckBox61.Value
Range("AM" & L).Value = CheckBox62.Value
Range("AN" & L).Value = CheckBox63.Value
Range("AO" & L).Value = TextBox10.Value
Range("AP" & L).Value = CheckBox64.Value
Range("AQ" & L).Value = CheckBox65.Value
Range("AR" & L).Value = CheckBox66.Value
Range("AS" & L).Value = CheckBox67.Value
Range("AT" & L).Value = CheckBox68.Value
Range("AU" & L).Value = CheckBox69.Value
Range("AV" & L).Value = CheckBox70.Value
Range("AW" & L).Value = CheckBox71.Value
Range("AX" & L).Value = CheckBox72.Value
Range("AY" & L).Value = TextBox11.Value
Range("AZ" & L).Value = ComboBox16.Value
Range("BA" & L).Value = ComboBox15.Value
Range("BB" & L).Value = TextBox14.Value
Range("BC" & L).Value = ComboBox16.Value
Range("BD" & L).Value = ComboBox17.Value
Range("BE" & L).Value = ComboBox18.Value
Range("BF" & L).Value = TextBox20.Value
Range("BG" & L).Value = CheckBox73.Value
Range("BH" & L).Value = CheckBox74.Value
Range("BI" & L).Value = CheckBox75.Value
Range("BJ" & L).Value = CheckBox76.Value
Range("BK" & L).Value = CheckBox77.Value
Range("BL" & L).Value = CheckBox78.Value
Range("BM" & L).Value = TextBox19.Value
Range("BN" & L).Value = CheckBox80.Value
Range("BO" & L).Value = CheckBox81.Value
Range("BP" & L).Value = CheckBox82.Value
Range("BQ" & L).Value = CheckBox83.Value
Range("BR" & L).Value = CheckBox84.Value
Range("Bs" & L).Value = TextBox12.Value
End With
With Sheets("Journées").Select
Dim La As Integer
La = Sheets("Journées").Range("d65536").End(xlUp).Row + 1
Range("d" & La).Value = ComboBox12.Value
Range("e" & La).Value = TextBox3.Value
Range("f" & La).Value = TextBox7.Value
Range("g" & La).Value = Format(CDate(TextBox5.Value), "dd-mm-yy")
Range("h" & La).Value = Format(CDate(TextBox13.Value), "dd-mm-yy")
End With
'rafraichir la fenêtre de saisie
Unload Me
UserForm1.Show vbModeless
End If
End Sub
Private Sub CommandButton3_Click() 'bouton modifier
Set ws = Sheets("Base")
Set wj = Sheets("Journées")
If MsgBox("Confirmez-vous la modification ?", vbYesNo, "Demande de confirmation") = vbYes Then
If Me.ComboBox12.ListIndex = -1 Then Exit Sub
ligne = Me.ComboBox12.ListIndex + 2
With ws
ws.Cells(ligne, "A") = Me.ComboBox12
ws.Cells(ligne, "B") = Me.TextBox3
ws.Cells(ligne, "C") = Me.ComboBox1
ws.Cells(ligne, "D") = Format(CDate(TextBox5), "dd-mm-yy")
ws.Cells(ligne, "E") = Me.ComboBox25
ws.Cells(ligne, "F") = Me.ComboBox26
ws.Cells(ligne, "G") = Format(CDate(TextBox21), "dd-mm-yy")
ws.Cells(ligne, "H") = Format(CDate(TextBox22), "dd-mm-yy")
ws.Cells(ligne, "I") = Format(CDate(TextBox23), "dd-mm-yy")
ws.Cells(ligne, "J") = Format(CDate(TextBox24), "dd-mm-yy")
ws.Cells(ligne, "K") = Format(CDate(TextBox25), "dd-mm-yy")
ws.Cells(ligne, "L") = Format(CDate(TextBox13), "dd-mm-yy")
ws.Cells(ligne, "M") = Me.ComboBox3
ws.Cells(ligne, "N") = Me.TextBox16
ws.Cells(ligne, "O") = Me.TextBox7
ws.Cells(ligne, "P") = Me.ComboBox19
ws.Cells(ligne, "Q") = Me.ComboBox22
ws.Cells(ligne, "R") = Me.ComboBox21
ws.Cells(ligne, "S") = Me.CheckBox42
ws.Cells(ligne, "T") = Me.CheckBox43
ws.Cells(ligne, "U") = Me.CheckBox44
ws.Cells(ligne, "V") = Me.CheckBox45
ws.Cells(ligne, "W") = Me.CheckBox46
ws.Cells(ligne, "X") = Me.CheckBox47
ws.Cells(ligne, "Y") = Me.CheckBox48
ws.Cells(ligne, "Z") = Me.CheckBox49
ws.Cells(ligne, "AA") = Me.CheckBox50
ws.Cells(ligne, "AB") = Me.TextBox17
ws.Cells(ligne, "AC") = Me.CheckBox52
ws.Cells(ligne, "AD") = Me.CheckBox53
ws.Cells(ligne, "AE") = Me.CheckBox54
ws.Cells(ligne, "AF") = Me.CheckBox55
ws.Cells(ligne, "AG") = Me.CheckBox56
ws.Cells(ligne, "AH") = Me.CheckBox57
ws.Cells(ligne, "AI") = Me.TextBox18
ws.Cells(ligne, "AJ") = Me.CheckBox59
ws.Cells(ligne, "AK") = Me.CheckBox60
ws.Cells(ligne, "AL") = Me.CheckBox61
ws.Cells(ligne, "AM") = Me.CheckBox62
ws.Cells(ligne, "AN") = Me.CheckBox63
ws.Cells(ligne, "AO") = Me.TextBox10
ws.Cells(ligne, "AP") = Me.CheckBox64
ws.Cells(ligne, "AQ") = Me.CheckBox65
ws.Cells(ligne, "AR") = Me.CheckBox66
ws.Cells(ligne, "AS") = Me.CheckBox67
ws.Cells(ligne, "AT") = Me.CheckBox68
ws.Cells(ligne, "AU") = Me.CheckBox69
ws.Cells(ligne, "AV") = Me.CheckBox70
ws.Cells(ligne, "AW") = Me.CheckBox71
ws.Cells(ligne, "AX") = Me.CheckBox72
ws.Cells(ligne, "AY") = Me.TextBox11
ws.Cells(ligne, "AZ") = Me.ComboBox16
ws.Cells(ligne, "BA") = Me.ComboBox15
ws.Cells(ligne, "BB") = Me.TextBox14
ws.Cells(ligne, "BC") = Me.ComboBox16
ws.Cells(ligne, "BD") = Me.ComboBox17
ws.Cells(ligne, "BE") = Me.ComboBox18
ws.Cells(ligne, "BF") = Me.TextBox20
ws.Cells(ligne, "BG") = Me.CheckBox73
ws.Cells(ligne, "BH") = Me.CheckBox74
ws.Cells(ligne, "BI") = Me.CheckBox75
ws.Cells(ligne, "BJ") = Me.CheckBox76
ws.Cells(ligne, "BK") = Me.CheckBox77
ws.Cells(ligne, "BL") = Me.CheckBox78
ws.Cells(ligne, "BM") = Me.TextBox19
ws.Cells(ligne, "BN") = Me.CheckBox80
ws.Cells(ligne, "BO") = Me.CheckBox81
ws.Cells(ligne, "BP") = Me.CheckBox82
ws.Cells(ligne, "BQ") = Me.CheckBox83
ws.Cells(ligne, "BR") = Me.CheckBox84
ws.Cells(ligne, "Bs") = Me.TextBox12
End With
If Me.ComboBox12.ListIndex = -1 Then Exit Sub
ligne = Me.ComboBox12.ListIndex + 2
With wj
wj.Cells(ligne, "d") = Me.ComboBox12
wj.Cells(ligne, "e") = Me.TextBox3
wj.Cells(ligne, "f") = Me.TextBox7
wj.Cells(ligne, "g") = Format(CDate(TextBox5), "dd-mm-yy")
wj.Cells(ligne, "h") = Format(CDate(TextBox13), "dd-mm-yy")
End With
MsgBox "La modification s'est correctement déroulée !"
End If
Unload Me
UserForm1.Show vbModeless
End Sub
Bonjour,
ric
- Messages
- 2'417
- Excel
- 2019
- Inscrit
- 13/07/2017
- Emploi
- Formateur, animateur,tech.informatique
Bonjour toutes et tous
-@tester
- aperçu les autres sont à modifier également
ws.Cells(ligne, "G") = Format(TextBox21, "dd-mm-yy")Edit: bonjour Ric, no soucy -;)
crdlt,
André
Bonjour,
Tu utilises un tableau structuré > c'est excellent ...
Il faut placer le bon format de date dans toutes les cellules de toutes les colonnes qui vont recevoir une date ...
Tu peux le faire rapidement en faisant de la sélection multiple > puis appliquer le format désiré ...
Une fois cela fait, si des dates ne s'adaptent pas > sélectionne à tour de rôle une cellule > F2 > Enter > la date va se convertir au bon format ...
Par précaution > enregistre ton fichier ...
Maintenant que ton tableau est prêt à être modifié et prêt à y ajouter des données > il reste le code à modifier ...
Il faudra modifier les lignes concernant les dates > et ceci dans les 2 macros > CommandButton3 (Modifier) et CommandButton2 (Ajouter) ...
Je présume qu'il n'y aura pas nécessairement de date dans tous les "TextBox" concernant les dates ...
Pour éviter les erreurs de conversion quand le texbox sera vide ...
Un exemple :
If Me.TextBox3 <> "" Then: ws.Cells(ligne, "B") = CDate(Me.TextBox3): Else ws.Cells(ligne, "B") = ""Dans cet exemple > si "Textbox3" n'est pas vide (différend de vide) > la date au format texte du textbox sera convertie en format de date numérique puis écrite dans la cellule > sinon > la cellule sera vidée ou restera vide ...
Je te laisse corriger ton code (TextBox3, 5, 21 à 25 des 2 macros) et tester la chose ...
ric
EDIT : bonjour Andre13 > je n'ai pas vu ta réponse > je n'avais pas actualisé mon navigateur ...
Bonjour ric,
merci, d'avoir pris le temps de voir mon formulaire.J'ai rajouté se que vous m'aviez proposé.
Comme je l'ai dit je suis toute jeune dans le VBA et je ne comprend pas pourquoi je lui met with et en with et il ne l'accepte pas.
Private Sub CommandButton3_Click() 'bouton modifier
Set ws = Sheets("Base")
Set wj = Sheets("Journées")
If MsgBox("Confirmez-vous la modification ?", vbYesNo, "Demande de confirmation") = vbYes Then
If Me.ComboBox12.ListIndex = -1 Then Exit Sub
ligne = Me.ComboBox12.ListIndex + 2
With ws
ws.Cells(ligne, "A") = Me.ComboBox12
ws.Cells(ligne, "B") = Me.TextBox3
ws.Cells(ligne, "C") = Me.ComboBox1
If Me.TextBox5 <> "" Then
ws.Cells(ligne, "D") = Format(CDate(TextBox5), "dd-mm-yy")
Else
ws.Cells(ligne, "D") = ""
ws.Cells(ligne, "E") = Me.ComboBox25
ws.Cells(ligne, "F") = Me.ComboBox26
If Me.TextBox21 <> "" Then
ws.Cells(ligne, "G") = Format(CDate(TextBox21), "dd-mm-yy")
Else
ws.Cells(ligne, "G") = ""
If Me.TextBox22 <> "" Then
ws.Cells(ligne, "H") = Format(CDate(TextBox22), "dd-mm-yy")
Else: ws.Cells(ligne, "H") = ""
If Me.TextBox23 <> "" Then
ws.Cells(ligne, "I") = Format(CDate(TextBox23), "dd-mm-yy")
Else
ws.Cells(ligne, "I") = ""
If Me.TextBox24 <> "" Then
ws.Cells(ligne, "J") = Format(CDate(TextBox24), "dd-mm-yy")
Else
ws.Cells(ligne, "J") = ""
If Me.TextBox25 <> "" Then
ws.Cells(ligne, "K") = Format(CDate(TextBox25), "dd-mm-yy")
Else
ws.Cells(ligne, "K") = ""
If Me.TextBox13 <> "" Then
ws.Cells(ligne, "L") = Format(CDate(TextBox13), "dd-mm-yy")
Else
ws.Cells(ligne, "L") = ""
ws.Cells(ligne, "M") = Me.ComboBox3
ws.Cells(ligne, "N") = Me.TextBox16
ws.Cells(ligne, "O") = Me.TextBox7
ws.Cells(ligne, "P") = Me.ComboBox19
ws.Cells(ligne, "Q") = Me.ComboBox22
ws.Cells(ligne, "R") = Me.ComboBox21
ws.Cells(ligne, "S") = Me.CheckBox42
ws.Cells(ligne, "T") = Me.CheckBox43
ws.Cells(ligne, "U") = Me.CheckBox44
ws.Cells(ligne, "V") = Me.CheckBox45
ws.Cells(ligne, "W") = Me.CheckBox46
ws.Cells(ligne, "X") = Me.CheckBox47
ws.Cells(ligne, "Y") = Me.CheckBox48
ws.Cells(ligne, "Z") = Me.CheckBox49
ws.Cells(ligne, "AA") = Me.CheckBox50
ws.Cells(ligne, "AB") = Me.TextBox17
ws.Cells(ligne, "AC") = Me.CheckBox52
ws.Cells(ligne, "AD") = Me.CheckBox53
ws.Cells(ligne, "AE") = Me.CheckBox54
ws.Cells(ligne, "AF") = Me.CheckBox55
ws.Cells(ligne, "AG") = Me.CheckBox56
ws.Cells(ligne, "AH") = Me.CheckBox57
ws.Cells(ligne, "AI") = Me.TextBox18
ws.Cells(ligne, "AJ") = Me.CheckBox59
ws.Cells(ligne, "AK") = Me.CheckBox60
ws.Cells(ligne, "AL") = Me.CheckBox61
ws.Cells(ligne, "AM") = Me.CheckBox62
ws.Cells(ligne, "AN") = Me.CheckBox63
ws.Cells(ligne, "AO") = Me.TextBox10
ws.Cells(ligne, "AP") = Me.CheckBox64
ws.Cells(ligne, "AQ") = Me.CheckBox65
ws.Cells(ligne, "AR") = Me.CheckBox66
ws.Cells(ligne, "AS") = Me.CheckBox67
ws.Cells(ligne, "AT") = Me.CheckBox68
ws.Cells(ligne, "AU") = Me.CheckBox69
ws.Cells(ligne, "AV") = Me.CheckBox70
ws.Cells(ligne, "AW") = Me.CheckBox71
ws.Cells(ligne, "AX") = Me.CheckBox72
ws.Cells(ligne, "AY") = Me.TextBox11
ws.Cells(ligne, "AZ") = Me.ComboBox16
ws.Cells(ligne, "BA") = Me.ComboBox15
ws.Cells(ligne, "BB") = Me.TextBox14
ws.Cells(ligne, "BC") = Me.ComboBox16
ws.Cells(ligne, "BD") = Me.ComboBox17
ws.Cells(ligne, "BE") = Me.ComboBox18
ws.Cells(ligne, "BF") = Me.TextBox20
ws.Cells(ligne, "BG") = Me.CheckBox73
ws.Cells(ligne, "BH") = Me.CheckBox74
ws.Cells(ligne, "BI") = Me.CheckBox75
ws.Cells(ligne, "BJ") = Me.CheckBox76
ws.Cells(ligne, "BK") = Me.CheckBox77
ws.Cells(ligne, "BL") = Me.CheckBox78
ws.Cells(ligne, "BM") = Me.TextBox19
ws.Cells(ligne, "BN") = Me.CheckBox80
ws.Cells(ligne, "BO") = Me.CheckBox81
ws.Cells(ligne, "BP") = Me.CheckBox82
ws.Cells(ligne, "BQ") = Me.CheckBox83
ws.Cells(ligne, "BR") = Me.CheckBox84
ws.Cells(ligne, "Bs") = Me.TextBox12
End With
If Me.ComboBox12.ListIndex = -1 Then Exit Sub
ligne = Me.ComboBox12.ListIndex + 2
With wj
wj.Cells(ligne, "d") = Me.ComboBox12
wj.Cells(ligne, "e") = Me.TextBox3
wj.Cells(ligne, "f") = Me.TextBox7
If Me.TextBox5 <> "" Then
wj.Cells(ligne, "g") = Format(CDate(TextBox5), "dd-mm-yy")
Else
wj.Cells(ligne, "g") = ""
If Me.TextBox13 <> "" Then
wj.Cells(ligne, "H") = Format(CDate(TextBox13), "dd-mm-yy")
Else
wj.Cells(ligne, "H") = ""
End With
MsgBox "La modification s'est correctement déroulée !"
End If
Unload Me
UserForm1.Show vbModeless
End Sub
Bonjour,
À l'avenir > s.t.p > utilise le bouton </> pour mettre ton code sous balise ...
Si tu démarres un IF > il faudrait un End IF pour le fermer > idem With ... le code... End With ...
Un essai ...
Private Sub CommandButton3_Click() 'bouton modifier
Dim Ws As Worksheet
Dim WJ As Worksheet
Set Ws = Worksheets("Base")
Set WJ = Worksheets("Journées")
If MsgBox("Confirmez-vous la modification ?", vbYesNo, "Demande de confirmation") = vbYes Then
If Me.ComboBox12.ListIndex = -1 Then Exit Sub
ligne = Me.ComboBox12.ListIndex + 2
With Ws
.Cells(ligne, "A") = Me.ComboBox12
.Cells(ligne, "B") = Me.TextBox3
.Cells(ligne, "C") = Me.ComboBox1
If Me.TextBox5 <> "" Then
.Cells(ligne, "D") = Format(CDate(TextBox5), "dd-mm-yy")
Else
.Cells(ligne, "D") = ""
.Cells(ligne, "E") = Me.ComboBox25
.Cells(ligne, "F") = Me.ComboBox26
If Me.TextBox21 <> "" Then
.Cells(ligne, "G") = Format(CDate(TextBox21), "dd-mm-yy")
Else
.Cells(ligne, "G") = ""
If Me.TextBox22 <> "" Then
.Cells(ligne, "H") = Format(CDate(TextBox22), "dd-mm-yy")
Else
.Cells(ligne, "H") = ""
If Me.TextBox23 <> "" Then
.Cells(ligne, "I") = Format(CDate(TextBox23), "dd-mm-yy")
Else
.Cells(ligne, "I") = ""
If Me.TextBox24 <> "" Then
.Cells(ligne, "J") = Format(CDate(TextBox24), "dd-mm-yy")
Else
.Cells(ligne, "J") = ""
If Me.TextBox25 <> "" Then
.Cells(ligne, "K") = Format(CDate(TextBox25), "dd-mm-yy")
Else
.Cells(ligne, "K") = ""
If Me.TextBox13 <> "" Then
.Cells(ligne, "L") = Format(CDate(TextBox13), "dd-mm-yy")
Else
.Cells(ligne, "L") = ""
.Cells(ligne, "M") = Me.ComboBox3
.Cells(ligne, "N") = Me.TextBox16
.Cells(ligne, "O") = Me.TextBox7
.Cells(ligne, "P") = Me.ComboBox19
.Cells(ligne, "Q") = Me.ComboBox22
.Cells(ligne, "R") = Me.ComboBox21
.Cells(ligne, "S") = Me.CheckBox42
.Cells(ligne, "T") = Me.CheckBox43
.Cells(ligne, "U") = Me.CheckBox44
.Cells(ligne, "V") = Me.CheckBox45
.Cells(ligne, "W") = Me.CheckBox46
.Cells(ligne, "X") = Me.CheckBox47
.Cells(ligne, "Y") = Me.CheckBox48
.Cells(ligne, "Z") = Me.CheckBox49
.Cells(ligne, "AA") = Me.CheckBox50
.Cells(ligne, "AB") = Me.TextBox17
.Cells(ligne, "AC") = Me.CheckBox52
.Cells(ligne, "AD") = Me.CheckBox53
.Cells(ligne, "AE") = Me.CheckBox54
.Cells(ligne, "AF") = Me.CheckBox55
.Cells(ligne, "AG") = Me.CheckBox56
.Cells(ligne, "AH") = Me.CheckBox57
.Cells(ligne, "AI") = Me.TextBox18
.Cells(ligne, "AJ") = Me.CheckBox59
.Cells(ligne, "AK") = Me.CheckBox60
.Cells(ligne, "AL") = Me.CheckBox61
.Cells(ligne, "AM") = Me.CheckBox62
.Cells(ligne, "AN") = Me.CheckBox63
.Cells(ligne, "AO") = Me.TextBox10
.Cells(ligne, "AP") = Me.CheckBox64
.Cells(ligne, "AQ") = Me.CheckBox65
.Cells(ligne, "AR") = Me.CheckBox66
.Cells(ligne, "AS") = Me.CheckBox67
.Cells(ligne, "AT") = Me.CheckBox68
.Cells(ligne, "AU") = Me.CheckBox69
.Cells(ligne, "AV") = Me.CheckBox70
.Cells(ligne, "AW") = Me.CheckBox71
.Cells(ligne, "AX") = Me.CheckBox72
.Cells(ligne, "AY") = Me.TextBox11
.Cells(ligne, "AZ") = Me.ComboBox16
.Cells(ligne, "BA") = Me.ComboBox15
.Cells(ligne, "BB") = Me.TextBox14
.Cells(ligne, "BC") = Me.ComboBox16
.Cells(ligne, "BD") = Me.ComboBox17
.Cells(ligne, "BE") = Me.ComboBox18
.Cells(ligne, "BF") = Me.TextBox20
.Cells(ligne, "BG") = Me.CheckBox73
.Cells(ligne, "BH") = Me.CheckBox74
.Cells(ligne, "BI") = Me.CheckBox75
.Cells(ligne, "BJ") = Me.CheckBox76
.Cells(ligne, "BK") = Me.CheckBox77
.Cells(ligne, "BL") = Me.CheckBox78
.Cells(ligne, "BM") = Me.TextBox19
.Cells(ligne, "BN") = Me.CheckBox80
.Cells(ligne, "BO") = Me.CheckBox81
.Cells(ligne, "BP") = Me.CheckBox82
.Cells(ligne, "BQ") = Me.CheckBox83
.Cells(ligne, "BR") = Me.CheckBox84
.Cells(ligne, "Bs") = Me.TextBox12
End If
End If
End If
End If
End If
End If
End With
If Me.ComboBox12.ListIndex = -1 Then Exit Sub
ligne = Me.ComboBox12.ListIndex + 2
With WJ
.Cells(ligne, "d") = Me.ComboBox12
.Cells(ligne, "e") = Me.TextBox3
.Cells(ligne, "f") = Me.TextBox7
If Me.TextBox5 <> "" Then
.Cells(ligne, "g") = Format(CDate(TextBox5), "dd-mm-yy")
Else
.Cells(ligne, "g") = ""
If Me.TextBox13 <> "" Then
.Cells(ligne, "H") = Format(CDate(TextBox13), "dd-mm-yy")
Else
.Cells(ligne, "H") = ""
End If
End If
End With
MsgBox "La modification s'est correctement déroulée !"
End If
End If
Unload Me
UserForm1.Show vbModeless
End Subric
re,
j'ai ajouté les" en if ", sauf qu'il ne considère pas que ça soit une date. Il le prend en tant que texte
Bonjour,
Ceci ne fonctionnera pas Format(CDate(TextBox24), "dd-mm-yy") ...
Essai plutôt : CDate(TextBox24) > en donnant soit le format adhéquat aux cellules directement dans la feuille > soit un format "Standard"...
ric