Validation Textbox avant validation

  • Initiateur de la discussion Initiateur de la discussion XC2ONE
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

XC2ONE

XLDnaute Junior
Bonjour Le Forum,

Voilà, j'ai un USF avec 4 TextBox où sont saisies 4 Chiffres.

Le bouton valider va reporter ces saisies dans un tableau.

Je souhaiterais que la validation ne soit possible que si TextBox1 + TextBox2 = TextBox3 + TextBox4 sinon message d'alerte.

Merci par avance du code qu'il faudrait que j'intègre au niveau de ma validation

Bonne après-midi à tout le Forum
 
Bonjour tout le monde

simplement :

Private Sub CommandButton1_Click()
If TextBox1 + TextBox2 <> TextBox3 + TextBox4 Then
MsgBox 'pas bon'
Else
MsgBox 'tout bon'
End If
End Sub

Penses à vérifier si tes textbox contiennent bien des valeurs numériques : isnumeric(.....

A plus
 
Bonjour Pascal76 et bonjour Hervé,

J'ai bien rajouter votre code, mais ça ne fonctionne pas, voici le code complet


Private Sub cmdValide_Click()

Sheets('BDD').Cells(nb_contact + 2, 2) = CDbl(f_ent1.Value)
Sheets('BDD').Cells(nb_contact + 2, 3) = CDbl(f_ent2.Value)
Sheets('BDD').Cells(nb_contact + 2, 4) = CDbl(f_ent3.Value)
Sheets('BDD').Cells(nb_contact + 2, 5) = CDbl(f_ent4.Value)
Sheets('BDD').Cells(nb_contact + 2, 6) = CDbl(f_ent5.Value)
Sheets('BDD').Cells(nb_contact + 2, 7) = CDbl(f_ent6.Value)
Sheets('BDD').Cells(nb_contact + 2, 8) = CDbl(f_ent7.Value)
Sheets('BDD').Cells(nb_contact + 2, 9) = CDbl(f_ent8.Value)
Sheets('BDD').Cells(nb_contact + 2, 10) = CDbl(f_ent9.Value)
choix_OK = True
f_ent1.Value = 0
f_ent2.Value = 0
f_ent3.Value = 0
f_ent4.Value = 0
f_ent5.Value = 0
f_ent6.Value = 0
f_ent7.Value = 0
f_ent8.Value = 0
f_ent9.Value = 0
f_ent1.SetFocus

If f_ent1 + f_ent2 + f_ent3 + f_ent4 <> f_ent5 + f_ent6 + f_ent7 Then
MsgBox 'Le total des contacts n'est pas égal au total des dénouements, vérifier votre saisie !'
choix_OK = False
Unload MAJ_01
Else
MsgBox 'Ok, saisie correcte !'
End If

Unload MAJ_01

End Sub


Merci pour votre aide,
 
Re

perso j'aurais fait le tes de validation au début pas à la fin

Private Sub cmdValide_Click()

If CDbl(f_ent1.Value) + CDbl(f_ent2.Value)+ CDbl(f_ent3.Value) + fCDbl(f_ent4.Value) <> CDbl(f_ent5.Value) + CDbl(f_ent6.Value) + CDbl(f_ent7.Value) Then
MsgBox 'Le total des contacts n'est pas égal au total des dénouements, vérifier votre saisie !'
choix_OK = False
exit sub
End If

Sheets('BDD').Cells(nb_contact + 2, 2) = CDbl(f_ent1.Value)
Sheets('BDD').Cells(nb_contact + 2, 3) = CDbl(f_ent2.Value)
Sheets('BDD').Cells(nb_contact + 2, 4) = CDbl(f_ent3.Value)
Sheets('BDD').Cells(nb_contact + 2, 5) = CDbl(f_ent4.Value)
Sheets('BDD').Cells(nb_contact + 2, 6) = CDbl(f_ent5.Value)
Sheets('BDD').Cells(nb_contact + 2, 7) = CDbl(f_ent6.Value)
Sheets('BDD').Cells(nb_contact + 2, 8) = CDbl(f_ent7.Value)
Sheets('BDD').Cells(nb_contact + 2, 9) = CDbl(f_ent8.Value)
Sheets('BDD').Cells(nb_contact + 2, 10) = CDbl(f_ent9.Value)
choix_OK = True
f_ent1.Value = 0
f_ent2.Value = 0
f_ent3.Value = 0
f_ent4.Value = 0
f_ent5.Value = 0
f_ent6.Value = 0
f_ent7.Value = 0
f_ent8.Value = 0
f_ent9.Value = 0
f_ent1.SetFocus




Unload MAJ_01

End Sub
 
Bonsoir X2C, Pascal, Ashaar, le Forum

Pensez toujours à essayer d'être concis dans vos codes, une Petite Boucle Basée sur une Petite Variable Byte... Et Hop, tout çà :

Sheets('BDD').Cells(nb_contact + 2, 2) = CDbl(f_ent1.Value)
Sheets('BDD').Cells(nb_contact + 2, 3) = CDbl(f_ent2.Value)
Sheets('BDD').Cells(nb_contact + 2, 4) = CDbl(f_ent3.Value)
Sheets('BDD').Cells(nb_contact + 2, 5) = CDbl(f_ent4.Value)
Sheets('BDD').Cells(nb_contact + 2, 6) = CDbl(f_ent5.Value)
Sheets('BDD').Cells(nb_contact + 2, 7) = CDbl(f_ent6.Value)
Sheets('BDD').Cells(nb_contact + 2, 8) = CDbl(f_ent7.Value)
Sheets('BDD').Cells(nb_contact + 2, 9) = CDbl(f_ent8.Value)
Sheets('BDD').Cells(nb_contact + 2, 10) = CDbl(f_ent9.Value)
f_ent1.Value = 0
f_ent2.Value = 0
f_ent3.Value = 0
f_ent4.Value = 0
f_ent5.Value = 0
f_ent6.Value = 0
f_ent7.Value = 0
f_ent8.Value = 0
f_ent9.Value = 0

Devient :
Code:
Dim x As Byte

For x = 1 To 9
    Sheets('BDD'Â'Â').Cells(nb_contact + 2, x + 1) = CDbl(Me.Controls('f_ent' & x))
    Me.Controls('f_ent' & x) = ''
Next

C'est ça les Barbatrucs qui simplifient la vie VBAesque, il suffit d'y penser

@+Thierry

Message édité par: _Thierry, à: 09/03/2005 18:49
 
Pascal76, _Thierry,

Merci d'aller encore plus loin que ce que je demande, les loop en effet ça aide.

Sur des codes déjà réalisées, j'ai parfois peur de tout remanier quand ca marche déjà.

Je crois que j'ai un GROS nettoyage de code à faire avec toutes vos remarques utiles.

Merci et bonne soirée...
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
815
Réponses
3
Affichages
968
Réponses
2
Affichages
985
Retour