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 !

sten83

XLDnaute Occasionnel
Bonjour je rencontre un petit problème avec un code macro je ne comprend pas?
Ci-joint mon code
Voici le message d'erreur
Erreur d'éxécution -2147024809(80070057):
Objet spécifique introuvable

Merci pour votre aide.

Private Sub CmdValideInfoParc_Click()
Dim i As Byte
For i = 1 To 15
If Controls("TextBox" & i) = "" Then (c'est cette ligne qui pose problème!)
MsgBox "Vous devez remplir le champ " & Controls("label" & i)
Controls("Textbox" & i).SetFocus
Exit For
End If
Next i

With shtjanvier
.Range("AB1") = txtParc.Value
.Range("AB2") = txtCodeParc.Value
.Range("AB3") = txtDirection.Value
.Range("B58") = txtResponsable.Value
.Range("F8") = txtPayant1.Value
.Range("H8") = txtPayant2.Value
.Range("J8") = txtPayant3.Value
.Range("M7") = txtNpayant1.Value
.Range("O7") = txtNpayant2.Value
.Range("Q7") = txtNpayant3.Value
.Range("S7") = txtNpayant4.Value
.Range("U7") = txtNpayant5.Value
.Range("W7") = txtNpayant6.Value
.Range("Y7") = txtNpayant7.Value
.Range("F4") = CboAnnee.Value
.Range("A9") = txtDate.Value

End With
Unload Me

End Sub
 
Re : Code Erreur

Re,

Ah ben alors, sûr que ça ne peut pas marcher !

S'il n'y a que ces 15 Textbox sur l'USF, on peut utiliser ce type d'instruction pour remplacer la boucle for i= 1 to 15 :
Code:
For each ctrl in me.controls
    If TypeName(ctrl) = "TextBox" Then
        If ctrl = "" Then 
            MsgBox "Vous devez remplir le champ "   '***& Controls("label" & i) ' 
            ctrl.SetFocus
            Exit For
        end if
     end if
Next
Non testé ( pas de classeur joint)
S'il y avait encore des soucis, joignez un classeur sans données confidentielles.

A+
 
- 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
407
Réponses
3
Affichages
599
Retour