Erreur de compilation sur code placé après end sub dans usf

zombe

XLDnaute Occasionnel
Salut le forum

Je ne sais pas mais je rencontre un message d'erreur de compilation.
Avec les codes ci-dessous, lorsque je cherche à vérifier si débogage il y'a, je rencontre le message svt :
Seuls les commentaires peuvent apparaitre après end sub, end function ou end property.
Qu'estce qui ne va pas?
Code:
Private Sub TextBox11_Change()
Dim Valeur As String
    'C'est inutile de surcharger la fonction
   'Cette propriété doit être déclarée dans le design
   TextBox11.MaxLength = 10 'nb caractères maxi autorisé dans le textbox
   Valeur = Len(TextBox11)
    If Valeur = 2 Or Valeur = 5 Then
        TextBox11 = TextBox11 & "."
    ElseIf Valeur = 10 Then
         If Not IsDate(Format(Replace(TextBox11, ".", "/"), "yyyy/mm/dd")) Then
             MsgBox "Format incorrect"
             TextBox11 = ""
             Exit Sub
       End If
    End If
End Sub
Private Sub TextBox14_Change()
Dim Valeur As String
    'C'est inutile de surcharger la fonction
   'Cette propriété doit être déclarée dans le design
   TextBox14.MaxLength = 10 'nb caractères maxi autorisé dans le textbox
   Valeur = Len(TextBox14)
    If Valeur = 2 Or Valeur = 5 Then
        TextBox14 = TextBox14 & "."
    ElseIf Valeur = 10 Then
         If Not IsDate(Format(Replace(TextBox14, ".", "/"), "yyyy/mm/dd")) Then
             MsgBox "Format incorrect"
             TextBox14 = ""
             Exit Sub
         
       End If
    
    End If
End Sub
Private Sub TextBox15_Change()
Dim Valeur As String
    'C'est inutile de surcharger la fonction
   'Cette propriété doit être déclarée dans le design
   TextBox15.MaxLength = 10 'nb caractères maxi autorisé dans le textbox
   Valeur = Len(TextBox15)
    If Valeur = 2 Or Valeur = 5 Then
        TextBox15 = TextBox15 & "."
    ElseIf Valeur = 10 Then
         If Not IsDate(Format(Replace(TextBox15, ".", "/"), "yyyy/mm/dd")) Then
             MsgBox "Format incorrect"
             TextBox15 = ""
             Exit Sub
       End If
    
    End If
End Sub
Private Sub TextBox25_Change()
Dim Valeur As String
    'C'est inutile de surcharger la fonction
   'Cette propriété doit être déclarée dans le design
   TextBox25.MaxLength = 10 'nb caractères maxi autorisé dans le textbox
   Valeur = Len(TextBox25)
    If Valeur = 2 Or Valeur = 5 Then
        TextBox25 = TextBox25 & "."
    ElseIf Valeur = 10 Then
         If Not IsDate(Format(Replace(TextBox25, ".", "/"), "yyyy/mm/dd")) Then
             MsgBox "Format incorrect"
             TextBox25 = ""
             Exit Sub
       End If
    
    End If
End Sub
Private Sub TextBox31_Change()
Dim Valeur As String
    'C'est inutile de surcharger la fonction
   'Cette propriété doit être déclarée dans le design
   TextBox31.MaxLength = 10 'nb caractères maxi autorisé dans le textbox
   Valeur = Len(TextBox31)
    If Valeur = 2 Or Valeur = 5 Then
        TextBox31 = TextBox31 & "."
    ElseIf Valeur = 10 Then
         If Not IsDate(Format(Replace(TextBox31, ".", "/"), "yyyy/mm/dd")) Then
             MsgBox "Format incorrect"
             TextBox31 = ""
             Exit Sub
       End If
    
    End If
End Sub

Private Sub CommandButton1_Click()

Dim Ctl As Control
Dim Col As Integer, Lig As Integer
Dim Fr5 As String, Fr6 As String
Col = 3 'pour la colonne B
'Boucle sur tout les contrôles de l'userform
'If Not ControlerRemplir() Then Exit Sub
With Sheets("DONNE")
For Each Ctl In Me.Controls
If TypeOf Ctl Is msforms.TextBox Then
If Ctl.Tag <> "" And Ctl <> "" Then
Lig = Ctl.Tag
.Cells(Lig, Col).Value = Ctl.Text
End If
ElseIf TypeOf Ctl Is msforms.OptionButton Then
If Ctl.Value Then
'l'OptionButton est checker
Lig = Ctl.Tag
.Cells(Lig, Col).Value = Ctl.Caption
End If
ElseIf TypeOf Ctl Is msforms.ComboBox Then
Lig = Ctl.Tag
.Cells(Lig, Col).Value = Ctl.Text
ElseIf TypeOf Ctl Is msforms.CheckBox Then
If Ctl.Value Then
Lig = Ctl.Tag
If Ctl.Tag = 12 Then
Fr5 = Fr5 + IIf(Fr5 = "", Ctl.Caption, ", " & Fr5)
.Cells(Lig, Col).Value = Fr5
ElseIf Ctl.Tag = 22 Then
Fr6 = Fr6 + IIf(Fr6 = "", Ctl.Caption, ", " & Fr6)
.Cells(Lig, Col).Value = Fr6
End If
End If
End If
Next Ctl
End With
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Private Sub ComboBox6_exit(ByVal cancel As msforms.ReturnBoolean)
If ComboBox6 <> "" Then MultiPage1.Value = 1
End Sub

Private Sub TBoxIdp_AfterUpdate()
      If TypeCompte.Temporaire1.Caption = "PACK COMPTE2" And TBoxIdp.Value <> "" Then TBoxVp.SetFocus
End Sub

Private Sub TextBox23_exit(ByVal cancel As msforms.ReturnBoolean)
If TextBox23 <> "" Then InfoCplement.Show
End Sub

Private Sub UserForm_initialize()
TextBox1 = Date
TextBox2 = Sheets("DONNE").Range("h21")
TextBox34 = Date
TextBox35 = Sheets("DONNE").Range("h21")
ComboBox5.List = Sheets("PARAMETRE").Range("D5:D22").Value
ComboBox2.List = Sheets("PARAMETRE").Range("R452:R816").Value
ComboBox1.List = Sheets("PARAMETRE").Range("C5:C22").Value
ComboBox6.List = Sheets("PARAMETRE").Range("U101:U279").Value
ComboBox7.AddItem "25"
ComboBox7.AddItem "50"
ComboBox7.AddItem "NEANT"
'-------------------------------------------------------------------------------
TypeDeCompte = TypeCompte.Temporaire1.Caption

   If TypeCompte.Temporaire1.Caption = "COMPTE1" Then TypeDeCompte = TypeCompte.Temporaire1.Caption
   If TypeCompte.Temporaire1.Caption = "PACK COMPTE2" Then 
End Sub
Merci de m'aider à me corriger svp
 

zombe

XLDnaute Occasionnel
Re : Erreur de compilation sur code placé après end sub dans usf

Salut
Merci pour votre feedback.
Je ne pense pas que ce soit la cause de l'erreur.
Dans mon cas réel après le then, le code ci-dessous s'ajoute.
Malgré tout l'erreur de compilation demeur toujours.
Code:
TypeDeCompte = TypeCompte.Temporaire1.Caption
Cdlt
 

tototiti2008

XLDnaute Barbatruc
Re : Erreur de compilation sur code placé après end sub dans usf

Bonjour zombe, Bonjour Efgé :),

en indentant le code, ça devient plus lisible

...

Edit : Oups, pas bon

Bon, j'ai collé ton code dans un USF vide et l'erreur vient bien de ce que te dit Efgé...
 
Dernière édition:

Efgé

XLDnaute Barbatruc
Re : Erreur de compilation sur code placé après end sub dans usf

Re zombe, Bonjour Tototiti :)

Pour le problème de base :
Je pense que la fin de ton code devrait ressembler soit à ça:
VB:
If TypeCompte.Temporaire1.Caption = "PACK COMPTE2" Then
            TypeDeCompte = TypeCompte.Temporaire1.Caption
End If
End Sub
Soit à ça
VB:
If TypeCompte.Temporaire1.Caption = "PACK COMPTE2" Then _
               TypeDeCompte = TypeCompte.Temporaire1.Caption
End Sub
Mais certainement pas à ça:
VB:
If TypeCompte.Temporaire1.Caption = "PACK COMPTE2" Then
                TypeDeCompte = TypeCompte.Temporaire1.Caption
End Sub
Pour l(identation du code:
Il s'agit d'ajouter des tabulations devant les lignes afin de façiliter la lecture du code. Exemple

Il est plus difficile de lire ceci:
VB:
IPrivate Sub TextBox11_Change()
Dim Valeur As String
TextBox11.MaxLength = 10 'nb caractères maxi autorisé dans le textbox
Valeur = Len(TextBox11)
If Valeur = 2 Or Valeur = 5 Then
TextBox11 = TextBox11 & "."
ElseIf Valeur = 10 Then
If Not IsDate(Format(Replace(TextBox11, ".", "/"), "yyyy/mm/dd")) Then
MsgBox "Format incorrect"
TextBox11 = ""
Exit Sub
End If
End If
End Sub
que cela
VB:
Private Sub TextBox11_Change()
Dim Valeur As String
TextBox11.MaxLength = 10
Valeur = Len(TextBox11)
If Valeur = 2 Or Valeur = 5 Then
    TextBox11 = TextBox11 & "."
ElseIf Valeur = 10 Then
    If Not IsDate(Format(Replace(TextBox11, ".", "/"), "yyyy/mm/dd")) Then
        MsgBox "Format incorrect"
        TextBox11 = ""
        Exit Sub
    End If
End If
End Sub
Cordialement
 
Dernière édition:

Discussions similaires

Réponses
5
Affichages
407

Membres actuellement en ligne

Statistiques des forums

Discussions
312 229
Messages
2 086 425
Membres
103 206
dernier inscrit
diambote