Microsoft 365 add.range plante Excel

  • Initiateur de la discussion Initiateur de la discussion eric72
  • 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 !

eric72

XLDnaute Accro
Bonjour à tous,
je rencontre un problème pour ajouter une ligne à un tableau à partir de Userform avec ce code:
VB:
With Sheets("Id").Range("TbId").ListObject
            .ListRows.Add.Range.Value = Array(TxtInit, TxtMdp, Abs(ChbEffectif), Abs(ChbAbsence), Abs(ChbSemType), Abs(ChbAmplitude), Abs(ChbNbparTranche), Abs(ChbPosteService), _
             Abs(ChbCptHres), Abs(ChbPoste), Abs(ChbService), Abs(ChbJrOuv), Abs(ChbPlanning), Abs(ChbSoldeCompteurhr), Abs(ChbPersPres), Abs(ChbPrepaSalaire))
la macro échoue de manière aléatoire et en plus Excel se ferme tout seul, ç'est pourtant une méthode relativement simple et pourtant!!!
Avez-vous une idée du pourquoi?
Merci beaucoup pour votre aide
Eric
 

Pièces jointes

Solution
Et là j'i eu une lumière (si,si ça peut arriver!!!), à l'ouverture de mon fichier j'ai un Usf d'identification avec mot de passe avec le code suivant:
VB:
Private Sub BtValider_Click()
Dim tableau As Range
Dim MDP As String
Dim ID As Variant
Set tableau = ThisWorkbook.Worksheets("Id").ListObjects("TbId").DataBodyRange
ID = Application.Match(CbNom, Range("Tbid[Utilisateur]"), 0)
If CbNom = "" Then MsgBox "Vous devez saisir un nom d'utilisateur": Exit Sub
If TxtMdp = "" Then MsgBox "Vous devez saisir un Mot de Passe": Exit Sub
    MDP = WorksheetFunction.VLookup(CbNom, tableau, 2, False)
    
    If IsError(MDP) Then MsgBox "Mot de Passe inconnu": TxtMdp = "": Exit Sub
    If MDP <> TxtMdp Then MsgBox "Mot de Passe inconnu": TxtMdp = "": Exit Sub...
Bonjour,

Dans mon test, je n'arrive pas à faire planter le
With Sheets("Id").Range("TbId").ListObject​
.ListRows.Add.Range.Value​

Mais je plante allègrement dans le
With Range("TbEffectif").ListObject 'ajoute une ligne à TbEffectif​
.ListRows.Add.Range.Value​
car les formats de valeurs indiqués dans le Array ne sont pas valides pour les données ..​
Rajoutez temporairement ces lignes de code avant ad.range.value pour vérifier les données avant l'ajout :
VB:
c = 0
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtNom
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtPrenom
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbPoste
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(datenaissance)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDbl(TxtNbHeure)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & ChbOui
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtTaux
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtInit
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & Abs(ObFixe)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & Abs(ObRotation)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDbl(NbSemRot)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemTypeFixe
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType1
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType2
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType3
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType4
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType5
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType6
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(DateDebut)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(DatedebutFixe)
 
Bonjour,

Dans mon test, je n'arrive pas à faire planter le
With Sheets("Id").Range("TbId").ListObject​
.ListRows.Add.Range.Value​

Mais je plante allègrement dans le
With Range("TbEffectif").ListObject 'ajoute une ligne à TbEffectif​
.ListRows.Add.Range.Value​
car les formats de valeurs indiqués dans le Array ne sont pas valides pour les données ..​
Rajoutez temporairement ces lignes de code avant ad.range.value pour vérifier les données avant l'ajout :
VB:
c = 0
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtNom
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtPrenom
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbPoste
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(datenaissance)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDbl(TxtNbHeure)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & ChbOui
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtTaux
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtInit
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & Abs(ObFixe)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & Abs(ObRotation)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDbl(NbSemRot)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemTypeFixe
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType1
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType2
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType3
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType4
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType5
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType6
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(DateDebut)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(DatedebutFixe
[/QUOTE]
 
Bonjour,

Dans mon test, je n'arrive pas à faire planter le
With Sheets("Id").Range("TbId").ListObject​
.ListRows.Add.Range.Value​

Mais je plante allègrement dans le
With Range("TbEffectif").ListObject 'ajoute une ligne à TbEffectif​
.ListRows.Add.Range.Value​
car les formats de valeurs indiqués dans le Array ne sont pas valides pour les données ..​
Rajoutez temporairement ces lignes de code avant ad.range.value pour vérifier les données avant l'ajout :
VB:
c = 0
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtNom
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtPrenom
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbPoste
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(datenaissance)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDbl(TxtNbHeure)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & ChbOui
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtTaux
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtInit
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & Abs(ObFixe)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & Abs(ObRotation)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDbl(NbSemRot)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemTypeFixe
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType1
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType2
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType3
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType4
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType5
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType6
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(DateDebut)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(DatedebutFixe)
Bonjour Fanch55
Non ça ne plante pas c'est juste que j'ai retiré les obligations de remplir tous les champs du haut, si vous remplissez tous les champs du haut ca fonctionne.
C'est avec le TbId que ça plante mais c'est aléatoire (1/2, 1/5 ou une fois sur 10)
Je ne comprends pas
 
Bonjour,

Dans mon test, je n'arrive pas à faire planter le
With Sheets("Id").Range("TbId").ListObject​
.ListRows.Add.Range.Value​

Mais je plante allègrement dans le
With Range("TbEffectif").ListObject 'ajoute une ligne à TbEffectif​
.ListRows.Add.Range.Value​
car les formats de valeurs indiqués dans le Array ne sont pas valides pour les données ..​
Rajoutez temporairement ces lignes de code avant ad.range.value pour vérifier les données avant l'ajout :
VB:
c = 0
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtNom
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtPrenom
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbPoste
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(datenaissance)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDbl(TxtNbHeure)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & ChbOui
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtTaux
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & TxtInit
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & Abs(ObFixe)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & Abs(ObRotation)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDbl(NbSemRot)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemTypeFixe
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType1
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType2
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType3
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType4
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType5
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CbSemType6
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(DateDebut)
c = c + 1: Debug.Print Left([TbEffectif].ListObject.ListColumns(c), 20) & "=" & CDate(DatedebutFixe)
Ah j'avais oublié de vous dire, de plus je ne peux pas savoir d'ou vient le problème puisqu'il m'éjecte...
 
Comment puis je faire pour les vérifier avant???
Tu mets un point d'arrêt sur l'instruction qui plante, et au moment où l'exécution s'arrête tu regardes la valeur de chacune des données.



Je crois que tu as mis le nom de la feuille dans laquelle se trouve le TS "TbId". Tu peux le supprimer pour ne garder que ceci :
VB:
    With Range("TbId").ListObject  ' Ajoute une ligne à TbId

ps : à mon avis le With ne sert à rien ici. 😉
 
Tu mets un point d'arrêt sur l'instruction qui plante, et au moment où l'exécution s'arrête tu regardes la valeur de chacune des données.



Je crois que tu as mis le nom de la feuille dans laquelle se trouve le TS "TbId". Tu peux le supprimer pour ne garder que ceci :
VB:
    With Range("TbId").ListObject  ' Ajoute une ligne à TbId
Les textbox renvoient la bonne valeur, et les checkbox vrai ou faux, donc normal
Le problème c'est que le beug est aléatoire, alors comment faire?
 
- 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
Retour