Demander une date et y appliquer une condition

Bonjour,

Je debute sur excel et un peu d'aide serait la bienvenue.

J'ai besoin de demander la date de naissance du candidat puis la faire entrer dans une cellule, mais avec la condition que l'annee de naissance soit apres 1970 dans le cas inverse envoyer un message d'erreur et supprimer toutes les donnees deja entree.

Voici ce que j'ai fait pour l'instant:

Sub registration()

Dim Name As String

Name = InputBox("Enter you'r Name", "Name")

Range("B3").Value = Name

Dim First_Name As String

First_Name = InputBox("Enter you'r First Name")

Range("B4").Value = First_Name

Dim id As String

Dim number As Long

id = InputBox("Enter you'r number id")

If (Len(id) > 9) Then

MsgBox "too long number", vbCritical

id = Left(id, 9)

End If

number = CLng(id)

Range("B5").Value = number

Dim birth_date As Date

birth_date = InputBox("Enter you'r birthday in this order:MM/DD/YYYY")

Range("B6").Value = birth_date

End Sub

Merci beaucoup

Bonjour,

Code à tester :

Sub registration()
    Dim Name As String
    Dim First_Name As String
    Dim id As String
    Dim number As Long
    Dim birth_date As Date
    Name = InputBox("Enter you'r Name", "Name")
    First_Name = InputBox("Enter you'r First Name")
    id = InputBox("Enter you'r number id")
    If (Len(id) > 9) Then
        MsgBox "too long number", vbCritical
        id = Left(id, 9)
    End If
    number = CLng(id)
    birth_date = InputBox("Enter you'r birthday in this order:MM/DD/YYYY")
    If Year(birth_date) < 1971 Then
        MsgBox "Non enregistré"
        Exit Sub
    Else
        Range("B3").Value = Name
        Range("B4").Value = First_Name
        Range("B5").Value = number
        Range("B6").Value = birth_date
    End If
End Sub

Effectivement c'est ecrit beacoup plus clairement et merci pour la fonction concernant l'annee. Mais je n'ai pas compris pourquoi le exit sub

Salut Net13, le fil

Je pense que Raja a anticipé le fait que tu allais rajouter quelque chose après la dernière condition If

number = CLng(id)
    birth_date = InputBox("Enter you'r birthday in this order:MM/DD/YYYY")
    If Year(birth_date) < 1971 Then
        MsgBox "Non enregistré"
        Exit Sub
    Else
        Range("B3").Value = Name
        Range("B4").Value = First_Name
        Range("B5").Value = number
        Range("B6").Value = birth_date
    End If
    ' code ...
    ' code ...
End Sub

Mais si tu laisses le code tel quel il est vrai que c'est pas nécessaire.

Rechercher des sujets similaires à "demander date appliquer condition"