VBA // Erreur '91'

Ela1005 Messages postés 3 Statut Membre -  
Ela1005 Messages postés 3 Statut Membre -
Bonjour,

Après navigation sur le forum je n'ai pas réussi à trouver la solution à mon problème ..
J'essaie de créer un code qui m'affiche un userform pour consulter le dossier d'un agent si la valeur rentrée dans ma textbox existe dans mon tableau et sinon si la valeur de ma textbox n'existe pas dans mon tableau je voudrais que le code m'affiche un autre userform pour créer le dossier de l'agent.
Cependant l'erreur '91' arrive pour la ligne en gras ... Mais je ne comprends pas pourquoi, surtout que cela marchait correctement auparavant ..

Voici mon code :
Private Sub cmd_valider_Click()

Worksheets("Restrictions").Select
If Cells.Find(what:=txt_matricule.Text) Then
Msg_consultation.Show

ElseIf txt_matricule.Text <> Cells(65535, 1).Value Then
Msg_création.Show
End If

txt_matricule.Text = ""
matricule_agent.Hide
End Sub

Merci pour votre aide :)

2 réponses

  1. Gyrus Messages postés 3360 Statut Membre 526
     
    Bonjour,

    Essaie comme cela
    Private Sub cmd_valider_Click()
    Dim C As Range
    With Worksheets("Restrictions")
    Set C = .Cells.Find(txt_matricule.Text, , xlValues, xlWhole)
    If Not C Is Nothing Then
    If C <> "" Then Msg_consultation.Show
    Else
    Msg_création.Show
    End If
    txt_matricule.Text = ""
    matricule_agent.Hide
    End With
    End Sub

    A+
    1
  2. Ela1005 Messages postés 3 Statut Membre
     
    Super merci beaucoup ça marche comme cela !
    0