1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
Private Sub CommandButton1_Click()
Dim L As Integer
Dim barre As Integer
Dim objControl As Control
Dim Cell As Range
barre = InStr(1, TextBox1, "/") + 1
'tester la valeur de textbox1 pour le formater comme date courte
If Not Mid(TextBox1, 1, 2) <= 31 Or Not Mid(TextBox1, 4, 2) <= 12 Or Not CBool(InStr(barre, TextBox1.Text, "/")) Or Not Right(TextBox1, 4) >= 2017 Then
MsgBox "veuillez inserer la date normal", vbOKOnly + vbInformation, "VALIDATION"
Exit Sub
Else 'permettre d'inserer les saisies dans la feuille active
If MsgBox("Confirmez-vous l'insertion de ce nouveau contact?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then
L = Sheets("Feuil1").Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & L).Value = TextBox1
End If
End If
'pour vider les textbox
For Each objControl In UserForm1.Controls
If TypeOf objControl Is MSForms.TextBox Then
objControl.Text = ""
End If
Next
'Supprimer tous les espaces superflus (la cellule se formate en date courte)
For Each Cell In ActiveSheet.UsedRange
Cell = Application.WorksheetFunction.Trim(Cell)
Next
End Sub |
Partager