Microsoft 365 Décalage de ligne lors de la saisie

Marvin57

XLDnaute Occasionnel
Bonjour à tout le monde,

j'ai un petit soucis lors de la saisie et validation de mes données vers un tableau structuré.

C'est à dire :

Lorsque je saisi les données dans mon userform et que je clique sur valider, il me m'inscrit les données à la suite de mon tableau structuré au lieu de le faire une ligne au dessus.

Voici le code qui sert à valider cela.

J'espère que cela va vous aider à comprendre mon problème car mon fichier est très volumineux et difficile a transmettre.

Le tableau structuré de l'onglet "POINTS" se nomme "Tableau28" si vous avez besoin de cette info.
Le tableau "Tableau28" démarre à la ligne A2 de l'onglet "POINTS".

Private Sub VALIDATION_Click() 'Valider l'enregistrement des points saisis
Dim Wtc As Worksheet
Application.ScreenUpdating = False
Set Wtc = Sheets("POINTS")
If VALIDATION.Caption = "VALIDER" Then
Dl = Wtc.Range("A" & Rows.Count).End(xlUp).Row + 1
If Dl = 2 Then
Wtc.Cells(Dl, 1).Value = 1
Else
Wtc.Cells(Dl, 1).Value = Application.WorksheetFunction.Max(Wtc.Range("A2:A" & Dl).Value) + 1
End If
Wtc.Cells(Dl, 2).Value = CDate(Me.TextBox1.Value)
Wtc.Cells(Dl, 2).NumberFormat = "m/d/yyyy"
Wtc.Cells(Dl, 3).Value = CDate(Me.TextBox2.Value)
Wtc.Cells(Dl, 3).NumberFormat = "m/d/yyyy"
Wtc.Cells(Dl, 4).Value = CDate(Me.TextBox3.Value)
Wtc.Cells(Dl, 4).NumberFormat = "m/d/yyyy"
Wtc.Cells(Dl, 5).Value = Me.ComboBox1.Value
Wtc.Cells(Dl, 6).Value = Me.ComboBox2.Value
Wtc.Cells(Dl, 7).Value = Me.ComboBox3.Value
Wtc.Cells(Dl, 8).Value = Me.TextBox4.Value
If Me.OptionButton1 = True Then Wtc.Cells(Dl, 9).Value = Me.TextBox5.Value
If Me.OptionButton2 = True Then Wtc.Cells(Dl, 10).Value = Me.TextBox5.Value

Actualiser_Affiche
MsgBox " Points enregistrés"
Else
Dl = Wtc.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Dl
If Me.lbltc.Caption = Wtc.Cells(i, 1).Value Then
Wtc.Range(Wtc.Cells(i, 2), Wtc.Cells(i, 10)) = ""
Wtc.Cells(i, 2).Value = CDate(Me.TextBox1.Value)
Wtc.Cells(i, 2).NumberFormat = "m/d/yyyy"
Wtc.Cells(i, 3).Value = CDate(Me.TextBox2.Value)
Wtc.Cells(i, 3).NumberFormat = "m/d/yyyy"
Wtc.Cells(i, 4).Value = CDate(Me.TextBox3.Value)
Wtc.Cells(i, 4).NumberFormat = "m/d/yyyy"
Wtc.Cells(i, 5).Value = Me.ComboBox1.Value
Wtc.Cells(i, 6).Value = Me.ComboBox2.Value
Wtc.Cells(i, 7).Value = Me.ComboBox3.Value
Wtc.Cells(i, 8).Value = Me.TextBox4.Value
If Me.OptionButton1 = True Then Wtc.Cells(i, 9).Value = Me.TextBox5.Value
If Me.OptionButton2 = True Then Wtc.Cells(i, 10).Value = Me.TextBox5.Value
Actualiser_Affiche
RAZ
Exit For
End If
Next
Me.LblTypeConge = "Points donnés "
Me.OptionButton1 = True
VALIDATION.Caption = "VALIDER"
VALIDATION.BackColor = &HFF00&
MsgBox " Points donnés modifiés"
End If


End Sub

Merci d'avance à vous pour vos infos et rectifications.

Marvin57
 

Dranreb

XLDnaute Barbatruc
Bonjour.
Conseil: rangez vos valeurs dans un Tableau des Valeurs de la Ligne déclaré: Dim TVL(1 To 1, 1 To 10)
À la fin, pour ajouter une ligne: Wtc.ListObjects(1).ListRows.Add.Range.Value = TVL
Pour modifier une ligne existante: Wtc.ListObjects(1).ListRows(i).Range.Value = TVL
 

Marvin57

XLDnaute Occasionnel
Bonjour.
Conseil: rangez vos valeurs dans un Tableau des Valeurs de la Ligne déclaré: Dim TVL(1 To 1, 1 To 10)
À la fin, pour ajouter une ligne: Wtc.ListObjects(1).ListRows.Add.Range.Value = TVL
Pour modifier une ligne existante: Wtc.ListObjects(1).ListRows(i).Range.Value = TVL
Bonjour Dranreb,

Merci pour votre retour et infos.

Mais je ne comprends pas !

Comment dois-je modifier ou placer les infos que vous donnez SVP.

Merci
 

Dranreb

XLDnaute Barbatruc
Commencez peut être par remplacer vos Wtc.Cells(L, C).Value = par des TVL(1, C) =
Notez que j'ai un gros module de classe qui saurait le faire si on donne à l'UserForm_Initialize la correspondance entre les contrôles concernés et les colonnes du tableau.
 
Dernière édition:

Dranreb

XLDnaute Barbatruc
Moi je vous l'ai dit. Si vous en voulez plus joignez un classeur épuré.
Peut être auriez vous intérêt au lieu d'un Dim Wtc As Worksheet: Set Wtc = Sheets("POINTS")
à utiliser un Dim LOt As ListObject: Set LOt = Sheets("POINTS").ListObjects(1)
 

Marvin57

XLDnaute Occasionnel
Moi je vous l'ai dit. Si vous en voulez plus joignez un classeur épuré.
Peut être auriez vous intérêt au lieu d'un Dim Wtc As Worksheet: Set Wtc = Sheets("POINTS")
à utiliser un Dim LOt As ListObject: Set LOt = Sheets("POINTS").ListObjects(1)
Re Dranreb,

voici un fichier exemple afin de comprendre ma demande.
Comme vous verrez, il m'inscrit la saisie de données une ligne en-dessous du tableau.

Merci pour votre aide et A+
Marvin57
 

Pièces jointes

  • Marvin57-A.xlsm
    78 KB · Affichages: 4

vgendron

XLDnaute Barbatruc
hello

Puisque tu as une table structurée.. autant travailler avec dans le code
VB:
Private Sub VALIDATION_Click() 'Valider l'enregistrement des congés saisis
    Dim Wtc As Worksheet
    Application.ScreenUpdating = False
    
    Set Wtc = Sheets("POINTS")
    With Wtc.ListObjects(1)
        If VALIDATION.Caption = "VALIDER" Then
            .ListRows.Add
            ligne = .ListRows.Count
        Else
            Set trouve = .ListColumns(1).Range.Find(Me.lbltc.Caption, lookat:=xlWhole)
            If Not trouve Is Nothing Then
                ligne = trouve.Row - .Range.Row
            End If
        End If
        
        .DataBodyRange(ligne, 1) = WorksheetFunction.Max(.ListColumns(1).DataBodyRange) + 1
        .DataBodyRange(ligne, 2).Value = CDate(Me.TextBox1.Value)
        .DataBodyRange(ligne, 2).NumberFormat = "m/d/yyyy"
        .DataBodyRange(ligne, 3).Value = CDate(Me.TextBox2.Value)
        .DataBodyRange(ligne, 3).NumberFormat = "m/d/yyyy"
        .DataBodyRange(ligne, 4).Value = CDate(Me.TextBox3.Value)
        .DataBodyRange(ligne, 4).NumberFormat = "m/d/yyyy"
        .DataBodyRange(ligne, 5).Value = Me.ComboBox1.Value
        .DataBodyRange(ligne, 6).Value = Me.ComboBox2.Value
        .DataBodyRange(ligne, 7).Value = Me.ComboBox3.Value
        .DataBodyRange(ligne, 8).Value = Me.TextBox4.Value
        If Me.OptionButton1 = True Then .DataBodyRange(ligne, 9).Value = Me.TextBox5.Value
        If Me.OptionButton2 = True Then .DataBodyRange(ligne, 10).Value = Me.TextBox5.Value
    End With
    MsgBox " Points demandés enregistrés"
    Me.LblTypePoints = "Points payés "
    Me.OptionButton1 = True
    VALIDATION.Caption = "VALIDER"
    VALIDATION.BackColor = &HFF00&
    MsgBox " Points de l'élève modifiés"

    Sheets("POINTS").Activate
    Application.ScreenUpdating = True
    Unload Me
    
End Sub
 

Dranreb

XLDnaute Barbatruc
Retrouvé avec plaisir un calendrier qui venait de moi ;)
Mais pourquoi y avoir ajouté un bouton QUITTER ? La croix de fermeture ou la touche Echap faisait déjà le taf, non ? Remarquez, j'en ai maintenant une version permettant de saisir aussi l'heure …
Bon je retourne à l'objet due la discussion. À plus …
(Remarque: vous auriez intérêt à renommer tous vos contrôles d'un nom mnémonique, ce serait bien plus facile de s'y retrouver que de chaque fois chercher …)
 
Dernière édition:

vgendron

XLDnaute Barbatruc
hello Bernard

@Marvin57
et pour éviter le double message à l'enregistrement

VB:
Private Sub VALIDATION_Click() 'Valider l'enregistrement des congés saisis
    Dim Wtc As Worksheet
    Application.ScreenUpdating = False
    
    Set Wtc = Sheets("POINTS")
    With Wtc.ListObjects(1)
        If VALIDATION.Caption = "VALIDER" Then
            .ListRows.Add
            ligne = .ListRows.Count
            Message = "Points demandés enregistrés"
        Else
            Set trouve = .ListColumns(1).Range.Find(Me.lbltc.Caption, lookat:=xlWhole)
            If Not trouve Is Nothing Then
                ligne = trouve.Row - .Range.Row
            End If
            Message = "Points de l'élève modifiés"
        End If
        
        .DataBodyRange(ligne, 1) = WorksheetFunction.Max(.ListColumns(1).DataBodyRange) + 1
        .DataBodyRange(ligne, 2).Value = CDate(Me.TextBox1.Value)
        .DataBodyRange(ligne, 2).NumberFormat = "m/d/yyyy"
        .DataBodyRange(ligne, 3).Value = CDate(Me.TextBox2.Value)
        .DataBodyRange(ligne, 3).NumberFormat = "m/d/yyyy"
        .DataBodyRange(ligne, 4).Value = CDate(Me.TextBox3.Value)
        .DataBodyRange(ligne, 4).NumberFormat = "m/d/yyyy"
        .DataBodyRange(ligne, 5).Value = Me.ComboBox1.Value
        .DataBodyRange(ligne, 6).Value = Me.ComboBox2.Value
        .DataBodyRange(ligne, 7).Value = Me.ComboBox3.Value
        .DataBodyRange(ligne, 8).Value = Me.TextBox4.Value
        If Me.OptionButton1 = True Then .DataBodyRange(ligne, 9).Value = Me.TextBox5.Value
        If Me.OptionButton2 = True Then .DataBodyRange(ligne, 10).Value = Me.TextBox5.Value
    End With
    MsgBox Message
    Me.LblTypePoints = "Points payés "
    Me.OptionButton1 = True
    VALIDATION.Caption = "VALIDER"
    VALIDATION.BackColor = &HFF00&

    Sheets("POINTS").Activate
    Application.ScreenUpdating = True
    Unload Me
    
End Sub

une remarque.. on est bien d'accord que dans le code fourni, à aucun moment, le bouton "Valider" change de texte en "Modifier"...?
 

Discussions similaires

Réponses
17
Affichages
334
Réponses
5
Affichages
400
Réponses
4
Affichages
209

Statistiques des forums

Discussions
312 206
Messages
2 086 219
Membres
103 158
dernier inscrit
laufin