IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Modifier une ligne avec des textbox et combobox [XL-2013]


Sujet :

Macros et VBA Excel

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut Modifier une ligne avec des textbox et combobox
    Bonjour à tous,

    Tout d'abord enchanté de vous rencontrer, il s'agit de mon premier message sur ce forum .

    Je suis désolé de vous déranger, j'aurai aimé résoudre le problème par moi même mais étant très débutant en VBA je suis complètement perdu.
    Actuellement en stage dans un hôpital (oui, je ne suis pas informaticien^^) , on m'as demander de faire un fichier globale pour le service qui prendrait toute les études dont nous somme le promoteur.
    On a réaliser une première base de donnée, mais on aurait aimer facilité l'ajout d’études (la macro est déjà fonctionnelle) mais aussi un bouton modifier (Rien n'est fonctionnelle) comme ça on peut verrouiller la base de donnée et ils ne peuvent rien supprimé (uniquement le pharmacien aura les codes).

    Nous avons trouvé un code pour le bouton modifier mais il n'utilisait que des textbox, mais à certain emplacement nous aimerions ajouter des combobox.

    Seul problème, text box et combobox ne se suivent pas dans l'ordre, du coup je ne sais comment faire pour modifier la ligne via textbox et combobox.

    Voici le bout de code et je vous laisse le fichier excel en pièce jointe pour voir a quoi ça ressemblerai :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    Option Explicit
     
    Dim Ws As Worksheet
     
     
    Private Sub ComboBox1_Change()
    ' Nom fournisseur
    Dim Ligne As Long
    Dim I As Integer
     
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
      Ligne = Me.ComboBox1.ListIndex + 2
      For I = 1 To 17
        Me.Controls("TextBox" & I) = Ws.Cells(Ligne, I + 1)
      Next I
     
    End Sub
     
    Private Sub ComboBox8_Change()
     
    End Sub
     
    Private Sub CommandButton1_Click()
    ' Valider
    Dim Ligne As Long
    Dim I As Integer
     
    Dim myPassword As String
    myPassword = "Lise1234"
    ThisWorkbook.Sheets("études").Unprotect Password:=myPassword
     
    If MsgBox("Etes-vous certain de vouloir MODIFIER cette étude ?", vbYesNo, "Demande de confirmation") = vbYes Then 'condition : si oui au message
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
      Ligne = Me.ComboBox1.ListIndex + 2
      For I = 1 To 17
        If Me.Controls("TextBox" & I).Visible = True Then
          Ws.Cells(Ligne, I + 1) = Me.Controls("TextBox" & I)
        End If
      Next I
      MsgBox ("Etude modifiée") 'Vous informant que le présent contact est insérer dans votre tableau Excel.
    Unload Me ' Vide et ferme l'Userform ( formulaire)
    ThisWorkbook.Sheets("études").Protect Password:=myPassword
    End If
    End Sub
     
     
    Private Sub CommandButton2_Click()
      Unload Mod_Fournisseur
    End Sub
     
    Private Sub Label1_Click()
     
    End Sub
     
    Private Sub TextBox1_Change()
     
    End Sub
     
    Private Sub TextBox7_Change()
     
    End Sub
     
    Private Sub UserForm_Initialize()
    Dim J As Long
    Dim I As Integer
     
      Set Ws = Sheets("études")
     
      With Me.ComboBox1
        For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
          .AddItem Ws.Range("A" & J)
        Next J
      End With
     
      For I = 1 To 17
        Me.Controls("TextBox" & I).Visible = False
        ReDim Preserve kase(I)
        Set kase(I).Bouton = Me.Controls("CheckBox" & I)
      Next I
     
    End Sub
    Je sais qu'actuellement le code ne prend pas en compte les combobox, j'aurai penser a rajouter genre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     Dim Y As Integer
    et utiliser le meme code que I pour les combobox mais vu que c'est sencer suivre A, B, C ,D , E , F ,.... Je ne pense pas que ça marchera
    Je vous remercie par avance pour l'aide que vous pourriez m'apporter.
    Fichiers attachés Fichiers attachés

  2. #2
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    Bonjour
    Tout d'abord il faut récupérer les informations déjà saisie au changement du combobox
    Une piste
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    Private Sub ComboBox1_Change()
      Dim plage As Range
      Dim cell As Range
      Dim codrecherché
       Set plage = Sheets("études").Range("A2:A" & [A65536].End(xlUp).Row)
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        TextBox1.Value = Cells(cell.Row, 2)
      'continuer à remplir les autres textbox
     End If
        Next cell
    End Sub

  3. #3
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut
    Bonjour BENNASR,

    Tout d'abord je vous remercie pour votre réponse,
    J'ai essayer du coup de remplir code comme ceux ci ,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    Option Explicit
     
    Dim Ws As Worksheet
     
     
    Private Sub ComboBox1_Change()
    'Private Sub ComboBox1_Change()
      Dim plage As Range
      Dim cell As Range
      Dim codrecherché
       Set plage = Sheets("études").Range("A2:A" & [A65536].End(xlUp).Row)
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        TextBox1.Value = Cells(cell.Row, 2)
        TextBox2.Value = Cells(cell.Row, 3)
        ComboBox2.Value = Cells(cell.Row, 4)
        TextBox3.Value = Cells(cell.Row, 5)
        TextBox4.Value = Cells(cell.Row, 6)
        Texbox5.Value = Cells(cell.Row, 7)
        ComboBox3.Value = Cells(cell.Row, 8)
        ComboBox4.Value = Cells(cell.Row, 9)
        TextBox6.Value = Cells(cell.Row, 10)
        ComboBox5.Value = Cells(cell.Row, 11)
        TextBox7.Value = Cells(cell.Row, 12)
        ComboBox6.Value = Cells(cell.Row, 13)
        ComboBox7.Value = Cells(cell.Row, 14)
        ComboBox8.Value = Cells(cell.Row, 15)
        ComboBox9.Value = Cells(cell.Row, 16)
        TextBox8.Value = Cells(cell.Row, 17)
        ComboBox10.Value = Cells(cell.Row, 18)
      'continuer à remplir les autres textbox
     End If
        Next cell
    End Sub
     
     
    Private Sub ComboBox8_Change()
     
    End Sub
     
    Private Sub CommandButton1_Click()
    ' Valider
    Dim Ligne As Long
    Dim I As Integer
     
    Dim myPassword As String
    myPassword = "Lise1234"
    ThisWorkbook.Sheets("études").Unprotect Password:=myPassword
     
    If MsgBox("Etes-vous certain de vouloir MODIFIER cette étude ?", vbYesNo, "Demande de confirmation") = vbYes Then 'condition : si oui au message
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
      Ligne = Me.ComboBox1.ListIndex + 2
      For I = 1 To 17
        If Me.Controls("TextBox" & "combobox" & I).Visible = True Then
          Ws.Cells(Ligne, I + 1) = Me.Controls("TextBox" & "Combobox" & I)
        End If
      Next I
      MsgBox ("Etude modifiée") 'Vous informant que le présent contact est insérer dans votre tableau Excel.
    Unload Me ' Vide et ferme l'Userform ( formulaire)
    ThisWorkbook.Sheets("études").Protect Password:=myPassword
    End If
    End Sub
     
     
    Private Sub CommandButton2_Click()
      Unload Mod_Fournisseur
    End Sub
     
    Private Sub Label1_Click()
     
    End Sub
     
    Private Sub TextBox1_Change()
     
    End Sub
     
    Private Sub TextBox7_Change()
     
    End Sub
     
    Private Sub UserForm_Initialize()
    Dim J As Long
    Dim I As Integer
     
      Set Ws = Sheets("études")
     
      With Me.ComboBox1
        For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
          .AddItem Ws.Range("A" & J)
        Next J
      End With
     
      For I = 1 To 17
        Me.Controls("TextBox" & I).Visible = False
        ReDim Preserve kase(I)
        Set kase(I).Bouton = Me.Controls("CheckBox" & I)
      Next I
     
    End Sub
    Mais lorsque j'execute la macro il me dit qu'il y a une erreur : erreur d'execution objet spécifié introuvable.
    Nom : screenerreurmacro.png
Affichages : 1908
Taille : 22,5 Ko

    Je suis sincerement desolé je comprend pas trop actuellement.
    Est ce que les "textbox" & "combobox" & I vont marcher ?

    en vous remerciant pour votre reponse =)

  4. #4
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    rebonjour
    lors de l'initialisation de ton usf je sais pas à quoi sert ce bout de code
    à supprimer ou à désactiver pour l'instant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     For I = 1 To 17
        Me.Controls("TextBox" & I).Visible = False
        ReDim Preserve kase(I)
        Set kase(I).Bouton = Me.Controls("CheckBox" & I)
      Next I
    Essayer de désactiver le bouton valider
    et ne laisser que l'initialisation et le combo change

  5. #5
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut
    Rebonjour,

    Merci encore pour ta reponse rapide =).

    Alors le code que j'ai supprimé empecher l'execution du code, mais il permettait de faire afficher la textbox ou la combobox en cochant la case.

    Du coup maintenant la récupération des données fonctionne, mais il y a une erreur d'execution lors que j'execute la maccro j'ai l'impression qu'il ne prend pas en compte la commande que j'ai entrer.

    voici le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    Private Sub CommandButton1_Click()
    ' Valider
    Dim Ligne As Long
    Dim I As Integer
     
    Dim myPassword As String
    myPassword = "Lise1234"
    ThisWorkbook.Sheets("études").Unprotect Password:=myPassword
     
    If MsgBox("Etes-vous certain de vouloir MODIFIER cette étude ?", vbYesNo, "Demande de confirmation") = vbYes Then 'condition : si oui au message
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
      Ligne = Me.ComboBox1.ListIndex + 2
      For I = 1 To 17
        If Me.Controls("TextBox" & "combobox" & I).Visible = True Then
          Ws.cells(Ligne, I + 1) = Me.Controls("TextBox" & "Combobox" & I)
        End If
      Next I
      MsgBox ("Etude modifiée") 'Vous informant que le présent contact est insérer dans votre tableau Excel.
    Unload Me ' Vide et ferme l'Userform ( formulaire)
    ThisWorkbook.Sheets("études").Protect Password:=myPassword
    End If
    End Sub
    et c'est cette ligne qui pose probleme :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     If Me.Controls("TextBox" & "combobox" & I).Visible = True Then
          Ws.cells(Ligne, I + 1) = Me.Controls("TextBox" & "Combobox" & I)
    Du coup j'ai essayer un truc comme ça :
    alors la modification fonctionne, mais ça me modifie la ligne juste en dessous, tu aurai une idee de code pour que ca me remplace la ligne deja existante ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    Option Explicit
     
    Dim Ws As Worksheet
     
     
    Private Sub ComboBox1_Change()
    'Private Sub ComboBox1_Change()
      Dim plage As Range
      Dim cell As Range
      Dim codrecherché
       Set plage = Sheets("études").Range("A2:A" & [A65536].End(xlUp).Row)
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        TextBox1.Value = cells(cell.Row, 2)
        TextBox2.Value = cells(cell.Row, 3)
        ComboBox2.Value = cells(cell.Row, 4)
        TextBox3.Value = cells(cell.Row, 5)
        TextBox4.Value = cells(cell.Row, 6)
        TextBox5.Value = cells(cell.Row, 7)
        ComboBox3.Value = cells(cell.Row, 8)
        ComboBox4.Value = cells(cell.Row, 9)
        TextBox6.Value = cells(cell.Row, 10)
        ComboBox5.Value = cells(cell.Row, 11)
        TextBox7.Value = cells(cell.Row, 12)
        ComboBox6.Value = cells(cell.Row, 13)
        ComboBox7.Value = cells(cell.Row, 14)
        ComboBox8.Value = cells(cell.Row, 15)
        ComboBox9.Value = cells(cell.Row, 16)
        TextBox8.Value = cells(cell.Row, 17)
        ComboBox10.Value = cells(cell.Row, 18)
      'continuer à remplir les autres textbox
     End If
        Next cell
    End Sub
     
     
    Private Sub ComboBox3_Change()
     
    End Sub
     
    Private Sub ComboBox8_Change()
     
    End Sub
     
    Private Sub CommandButton1_Click()
    ' Valider
    Dim L As Integer
    Dim myPassword As String
    myPassword = "Lise1234"
    ThisWorkbook.Sheets("études").Unprotect Password:=myPassword
     
     
    If MsgBox("Etes-vous certain de vouloir INSERER ce nouveau contact ?", vbYesNo, "Demande de confirmation") = vbYes Then 'condition : si oui au message
    L = Sheets("études").Range("a65536").End(xlUp).Row
     
    Range("A" & L).Value = ComboBox1 'Insère la donnée de la textbox1 dans la colonne B
    'et à suivre....
    Range("B" & L).Value = TextBox1
    Range("C" & L).Value = TextBox2
    Range("D" & L).Value = ComboBox2
    Range("E" & L).Value = TextBox3
    Range("F" & L).Value = TextBox4
    Range("G" & L).Value = TextBox5
    Range("H" & L).Value = ComboBox3
    Range("I" & L).Value = ComboBox4
    Range("J" & L).Value = TextBox6
    Range("K" & L).Value = ComboBox5
    Range("L" & L).Value = TextBox7
    Range("M" & L).Value = ComboBox6
    Range("N" & L).Value = ComboBox7
    Range("O" & L).Value = ComboBox8
    Range("P" & L).Value = ComboBox9
    Range("Q" & L).Value = TextBox8
    Range("Q" & L).Value = ComboBox10
    End If
     
    ThisWorkbook.Sheets("études").Protect Password:=myPassword
     
    ' Affiche une boîte de message
    MsgBox ("étude insérée dans la liste étude") 'Vous informant que le présent contact est insérer dans votre tableau Excel.
    Unload Me ' Vide et ferme l'Userform ( formulaire)
    End Sub
     
     
    Private Sub CommandButton2_Click()
      Unload Mod_Fournisseur
    End Sub
     
    Private Sub Label1_Click()
     
    End Sub
     
    Private Sub TextBox1_Change()
     
    End Sub
     
    Private Sub TextBox7_Change()
     
    End Sub
     
    Private Sub UserForm_Initialize()
    Dim J As Long
    Dim I As Integer
     
      Set Ws = Sheets("études")
     
      With Me.ComboBox1
        For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
          .AddItem Ws.Range("A" & J)
        Next J
      End With
     
     
     
    End Sub
    Mais du coup il me modifie la derniere ligne mais la ligne correspondante tu aurais une idée ?

    Merci beaucoup de ton aide

  6. #6
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    Re bonjour
    c'est sur il va remplacer la dernière ligne puisque tu écris ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    L = Sheets("études").Range("a65536").End(xlUp).Row
    Mais tu peux faire avec la même principe de combobox_change mais à l'inverse
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Private Sub CommandButton1_Click()
     Dim plage As Range
      Dim cell As Range
      Dim codrecherché
       Set plage = Sheets("études").Range("A2:A" & [A65536].End(xlUp).Row)
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        Cells(cell.Row, 2) = TextBox1.Value
      'continuer à remplir les autres textbox
     End If
        Next cell
     
    End Sub

  7. #7
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut
    Bonjour,

    Désolé j'était en train de manger,

    Du coup oui je comprend =) et pour le coup ton code marche du tonnerre merci beaucoup =).

    Je vais pouvoir focaliser sur la base de donnée maintenant =).

    Merci à bientot

  8. #8
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut
    Rebonjour,

    Finallement, j'ai un nouveau problème. Quand il y a très peu de lignes dans le tableau la fonction fonctionne parfaitement, mais la avec 75 lignes , la macro ne peut me récupérer les données, je ne comprend pas :/

    Auriez vous une idée ?

  9. #9
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    re
    en VBA ce qui est valable pour 3 lignes normalement valable pour plus de ligne et qui diffère peut être le temps d'exécution et pour améliorer ce temps tu peux ajouter en début de vode
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Application.ScreenUpdating = False
    et en fin de code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Application.ScreenUpdating = true
    ça n'a rien avoir avec ton problème , je le sais
    pour ton cas vérifiez s'il y a des lignes vides ???
    Aussi débutant et autodidacte en VBA donc fais attention

  10. #10
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut
    Re,

    ^^ Merci pour ta réponse je suis désolé je viens de la voir =).

    du coup voici le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    Option Explicit
     
    Dim Ws As Worksheet
     
     
    Private Sub ComboBox1_Change()
    'Private Sub ComboBox1_Change()
    Application.ScreenUpdating = False
      Dim plage As Range
      Dim cell As Range
      Dim codrecherché
       Set plage = Sheets("études").Range("A3:A" & [A65536].End(xlUp).Row)
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        TextBox1.Value = Cells(cell.Row, 2)
        TextBox2.Value = Cells(cell.Row, 3)
        ComboBox2.Value = Cells(cell.Row, 4)
        TextBox3.Value = Cells(cell.Row, 5)
        TextBox4.Value = Cells(cell.Row, 6)
        TextBox5.Value = Cells(cell.Row, 7)
        ComboBox3.Value = Cells(cell.Row, 8)
        ComboBox4.Value = Cells(cell.Row, 9)
        TextBox6.Value = Cells(cell.Row, 10)
        ComboBox5.Value = Cells(cell.Row, 11)
        TextBox7.Value = Cells(cell.Row, 12)
        ComboBox6.Value = Cells(cell.Row, 13)
        ComboBox7.Value = Cells(cell.Row, 14)
        ComboBox8.Value = Cells(cell.Row, 15)
        ComboBox9.Value = Cells(cell.Row, 16)
        TextBox8.Value = Cells(cell.Row, 17)
        ComboBox10.Value = Cells(cell.Row, 18)
      'continuer à remplir les autres textbox
     End If
        Next cell
        Application.ScreenUpdating = True
     
    End Sub
     
     
    Private Sub ComboBox3_Change()
     
    End Sub
     
    Private Sub ComboBox8_Change()
     
    End Sub
     
    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim myPassword As String
    myPassword = "Lise1234"
    ThisWorkbook.Sheets("études").Unprotect Password:=myPassword
     Dim plage As Range
      Dim cell As Range
      Dim codrecherché
       Set plage = Sheets("études").Range("A3:A" & [A65536].End(xlUp).Row)
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        Cells(cell.Row, 2) = TextBox1.Value
        Cells(cell.Row, 3) = TextBox2.Value
        Cells(cell.Row, 4) = ComboBox2.Value
        Cells(cell.Row, 5) = TextBox3.Value
        Cells(cell.Row, 6) = TextBox4.Value
        Cells(cell.Row, 7) = TextBox5.Value
        Cells(cell.Row, 8) = ComboBox3.Value
        Cells(cell.Row, 9) = ComboBox4.Value
        Cells(cell.Row, 10) = TextBox6.Value
        Cells(cell.Row, 11) = ComboBox5.Value
        Cells(cell.Row, 12) = TextBox7.Value
        Cells(cell.Row, 13) = ComboBox6.Value
        Cells(cell.Row, 14) = ComboBox7.Value
        Cells(cell.Row, 15) = ComboBox8.Value
        Cells(cell.Row, 16) = ComboBox9.Value
        Cells(cell.Row, 17) = TextBox8.Value
        Cells(cell.Row, 18) = ComboBox10.Value
     
      'continuer à remplir les autres textbox
     End If
        Next cell
     
     
    ThisWorkbook.Sheets("études").Protect Password:=myPassword
     
     
    ' Affiche une boîte de message
    MsgBox ("étude modifiée dans la liste étude")
    Unload Me ' Vide et ferme l'Userform ( formulaire)
    Application.ScreenUpdating = True
    End Sub
     
     
    Private Sub CommandButton2_Click()
      Unload Mod_Fournisseur
    End Sub
     
    Private Sub Label1_Click()
     
    End Sub
     
    Private Sub TextBox1_Change()
     
    End Sub
     
    Private Sub TextBox7_Change()
     
    End Sub
     
    Private Sub UserForm_Initialize()
    Dim J As Long
    Dim I As Integer
     
      Set Ws = Sheets("études")
     
      With Me.ComboBox1
        For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
          .AddItem Ws.Range("A" & J)
        Next J
      End With
     
     
     
    End Sub
    J'ai rajouter les items que tu m'as dit, mais pareille il ne me retrouve plus les cellules, alors que juste avant que je le colle dans mon fichier excel mere ça marcher sur 2-3 lignes ^^. quand je colle ma base de donnée ça marche plus non plus je comprend pas trop.
    Tu pense qu'il y a une erreur dans mon code ?

  11. #11
    Expert confirmé Avatar de BENNASR
    Homme Profil pro
    Responsable comptable & financier
    Inscrit en
    Décembre 2013
    Messages
    2 974
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Responsable comptable & financier
    Secteur : Finance

    Informations forums :
    Inscription : Décembre 2013
    Messages : 2 974
    Par défaut
    re
    pour ne pas avoir de surprise lors de l'appel de ce code utilise with.....end with
    n'oubliez pas d'ajouter un point devant cells

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    with sheets ("nomonglet")
    For Each cell In plage
     If cell.Value = codrecherché Then
        TextBox1.Value = .Cells(cell.Row, 2)
        TextBox2.Value = .Cells(cell.Row, 3)
        ComboBox2.Value = .Cells(cell.Row, 4)
        TextBox3.Value = .Cells(cell.Row, 5)
        TextBox4.Value = .Cells(cell.Row, 6)
        TextBox5.Value = .Cells(cell.Row, 7)
        ComboBox3.Value = .Cells(cell.Row, 8)
        ComboBox4.Value = .Cells(cell.Row, 9)
        TextBox6.Value = .Cells(cell.Row, 10)
        ComboBox5.Value = .Cells(cell.Row, 11)
        TextBox7.Value = .Cells(cell.Row, 12)
        ComboBox6.Value = .Cells(cell.Row, 13)
        ComboBox7.Value = .Cells(cell.Row, 14)
        ComboBox8.Value = .Cells(cell.Row, 15)
        ComboBox9.Value = .Cells(cell.Row, 16)
        TextBox8.Value = .Cells(cell.Row, 17)
        ComboBox10.Value = .Cells(cell.Row, 18)
      'continuer à remplir les autres textbox
     End If
        Next cell
    end with
    meme chose pour le reste du code
    cordialement

  12. #12
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut
    Hello BENNASR,

    Du coup ce matin, j'ai repris le fichier excel etant des donnée sensible j'ai pas le droit de les emporter à la maison. Du coup Avec 2 lignes ça marche mais avec ma base de donnée complete rien du tout je comprend pas.
    J'ai rajouter les lignes que tu m'as dit mais cela ne change rien c'est vraiment bizarre.

    alors que ça marche avec les 2 premiere lignes c'est bizarre

  13. #13
    Membre Expert
    Avatar de Igloobel
    Homme Profil pro
    Développeur ERP - VBA et Formateur bureautique
    Inscrit en
    Septembre 2005
    Messages
    1 871
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Développeur ERP - VBA et Formateur bureautique
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2005
    Messages : 1 871
    Billets dans le blog
    1
    Par défaut
    Bonjour,

    Quelle sont les différences de format entre ta ligne 2 qui fonctionne et ta ligne 3 qui fonctionne pas

    format de cellule, Espace insécable ...


    PS : j'ai pas ouvert ton fichier et regarder ton codr en diagonale
    c'est juste histoire d'ajouter de l'eau au moulin

  14. #14
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut
    Bonjour Igloobel,

    Du coup il s'agit d'un tableau standard. en Ligne 1 il n'y a pas de donné car présence des boutons , en ligne 2 c'est l'entete du tableau, et ligne 3 arrive les données.

    cela ce presente comme ceux ci :
    Nom : screenerreurmacro2.png
Affichages : 1750
Taille : 113,5 Ko

    et quand je lance mon bouton modifié : avant que j'utilise mes données ça marcher maintenant que j'ai rajouter mes lignes ça marches plus :'(.

    l'userform ressemble a ça :

    Nom : screenerreurmacro3.png
Affichages : 1842
Taille : 92,6 Ko

    et voici le dernier code utilisé :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    Private Sub ComboBox1_Change()
    'Private Sub ComboBox1_Change()
    Application.ScreenUpdating = False
      Dim plage As Range
      Dim cell As Range
      Dim codrecherché
       Set plage = Sheets("études").Range("A3:A" & [A65536].End(xlUp).Row)
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        TextBox1.Value = cells(cell.Row, 2)
        TextBox2.Value = cells(cell.Row, 3)
        ComboBox2.Value = cells(cell.Row, 4)
        TextBox3.Value = cells(cell.Row, 5)
        TextBox4.Value = cells(cell.Row, 6)
        TextBox5.Value = cells(cell.Row, 7)
        ComboBox3.Value = cells(cell.Row, 8)
        ComboBox4.Value = cells(cell.Row, 9)
        TextBox6.Value = cells(cell.Row, 10)
        ComboBox5.Value = cells(cell.Row, 11)
        TextBox7.Value = cells(cell.Row, 12)
        ComboBox6.Value = cells(cell.Row, 13)
        ComboBox7.Value = cells(cell.Row, 14)
        ComboBox8.Value = cells(cell.Row, 15)
        ComboBox9.Value = cells(cell.Row, 16)
        TextBox8.Value = cells(cell.Row, 17)
        ComboBox10.Value = cells(cell.Row, 18)
      'continuer à remplir les autres textbox
     End If
        Next cell
        Application.ScreenUpdating = True
     
    End Sub
     
     
    Private Sub ComboBox3_Change()
     
    End Sub
     
    Private Sub ComboBox8_Change()
     
    End Sub
     
    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim myPassword As String
    myPassword = "Lise1234"
    ThisWorkbook.Sheets("études").Unprotect Password:=myPassword
     Dim plage As Range
      Dim cell As Range
      Dim codrecherché
       Set plage = Sheets("études").Range("A3:A" & [A65536].End(xlUp).Row)
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        cells(cell.Row, 2) = TextBox1.Value
        cells(cell.Row, 3) = TextBox2.Value
        cells(cell.Row, 4) = ComboBox2.Value
        cells(cell.Row, 5) = TextBox3.Value
        cells(cell.Row, 6) = TextBox4.Value
        cells(cell.Row, 7) = TextBox5.Value
        cells(cell.Row, 8) = ComboBox3.Value
        cells(cell.Row, 9) = ComboBox4.Value
        cells(cell.Row, 10) = TextBox6.Value
        cells(cell.Row, 11) = ComboBox5.Value
        cells(cell.Row, 12) = TextBox7.Value
        cells(cell.Row, 13) = ComboBox6.Value
        cells(cell.Row, 14) = ComboBox7.Value
        cells(cell.Row, 15) = ComboBox8.Value
        cells(cell.Row, 16) = ComboBox9.Value
        cells(cell.Row, 17) = TextBox8.Value
        cells(cell.Row, 18) = ComboBox10.Value
     
      'continuer à remplir les autres textbox
     End If
        Next cell
     
     
    ThisWorkbook.Sheets("études").Protect Password:=myPassword
     
     
    ' Affiche une boîte de message
    MsgBox ("étude modifiée dans la liste étude")
    Unload Me ' Vide et ferme l'Userform ( formulaire)
    Application.ScreenUpdating = True
    End Sub
     
     
    Private Sub CommandButton2_Click()
      Unload Mod_Fournisseur
    End Sub
     
    Private Sub Label1_Click()
     
    End Sub
     
    Private Sub TextBox1_Change()
     
    End Sub
     
    Private Sub TextBox7_Change()
     
    End Sub
     
    Private Sub UserForm_Initialize()
    Dim J As Long
    Dim I As Integer
     
      Set Ws = Sheets("études")
     
      With Me.ComboBox1
        For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
          .AddItem Ws.Range("A" & J)
        Next J
      End With
     
     
     
    End Sub
    J'ai essayer de changer les valeurs mettre par exemple textbox.Value2 ou textbox.text j'ai essayer de changer les dim XX as String je me suis dis c'est un probleme de declaration de variable ou autres. mais j'avoue que je suis completement perdu la et c'est tres frustrant de voir que ça marche pour 2 lignes mais que ça marche plus maintenant.

  15. #15
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2018
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2018
    Messages : 9
    Par défaut
    Rebonjour,
    Du coup j'ai reussi à trouver une solution =) c'était un problème de déclaration de variables, du fait je penses que certaines variables sont en date, d'autre en chiffre, d'autre en texte etc.

    Du coup voici la solution :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    Private Sub ComboBox1_Change()
    'Private Sub ComboBox1_Change()
    Application.ScreenUpdating = False
      Dim plage As Variant
      Dim cell As Variant
      Set plage = Sheets("études").Range("A3:A" & [A65536].End(xlUp).Row)
      Dim codrecherché As String
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        TextBox1.Value = cells(cell.Row, 2)
        TextBox2.Value = cells(cell.Row, 3)
        ComboBox2.Value = cells(cell.Row, 4)
        TextBox3.Value = cells(cell.Row, 5)
        TextBox4.Value = cells(cell.Row, 6)
        TextBox5.Value = cells(cell.Row, 7)
        ComboBox3.Value = cells(cell.Row, 8)
        ComboBox4.Value = cells(cell.Row, 9)
        TextBox6.Value = cells(cell.Row, 10)
        ComboBox5.Value = cells(cell.Row, 11)
        TextBox7.Value = cells(cell.Row, 12)
        ComboBox6.Value = cells(cell.Row, 13)
        ComboBox7.Value = cells(cell.Row, 14)
        ComboBox8.Value = cells(cell.Row, 15)
        ComboBox9.Value = cells(cell.Row, 16)
        TextBox8.Value = cells(cell.Row, 17)
        ComboBox10.Value = cells(cell.Row, 18)
      'continuer à remplir les autres textbox
     End If
        Next cell
        Application.ScreenUpdating = True
     
    End Sub
     
     
    Private Sub ComboBox3_Change()
     
    End Sub
     
    Private Sub ComboBox8_Change()
     
    End Sub
     
    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim myPassword As String
    myPassword = "Lise1234"
    ThisWorkbook.Sheets("études").Unprotect Password:=myPassword
     Dim plage As Variant
      Dim cell As Variant
       Set plage = Sheets("études").Range("A3:A" & [A65536].End(xlUp).Row)
       Dim codrecherché As String
       codrecherché = ComboBox1.Value
      If Me.ComboBox1.ListIndex = -1 Then Exit Sub
    For Each cell In plage
     If cell.Value = codrecherché Then
        cells(cell.Row, 2) = TextBox1.Value
        cells(cell.Row, 3) = TextBox2.Value
        cells(cell.Row, 4) = ComboBox2.Value
        cells(cell.Row, 5) = TextBox3.Value
        cells(cell.Row, 6) = TextBox4.Value
        cells(cell.Row, 7) = TextBox5.Value
        cells(cell.Row, 8) = ComboBox3.Value
        cells(cell.Row, 9) = ComboBox4.Value
        cells(cell.Row, 10) = TextBox6.Value
        cells(cell.Row, 11) = ComboBox5.Value
        cells(cell.Row, 12) = TextBox7.Value
        cells(cell.Row, 13) = ComboBox6.Value
        cells(cell.Row, 14) = ComboBox7.Value
        cells(cell.Row, 15) = ComboBox8.Value
        cells(cell.Row, 16) = ComboBox9.Value
        cells(cell.Row, 17) = TextBox8.Value
        cells(cell.Row, 18) = ComboBox10.Value
     
      'continuer à remplir les autres textbox
     End If
        Next cell
     
     
    ThisWorkbook.Sheets("études").Protect Password:=myPassword
     
     
    ' Affiche une boîte de message
    MsgBox ("étude modifiée dans la liste étude")
    Unload Me ' Vide et ferme l'Userform ( formulaire)
    Application.ScreenUpdating = True
    End Sub
     
     
    Private Sub CommandButton2_Click()
      Unload Mod_Fournisseur
    End Sub
     
    Private Sub Label1_Click()
     
    End Sub
     
    Private Sub TextBox1_Change()
     
    End Sub
     
    Private Sub TextBox7_Change()
     
    End Sub
     
    Private Sub UserForm_Initialize()
    Dim J As Long
    Dim I As Integer
     
      Set Ws = Sheets("études")
     
      With Me.ComboBox1
        For J = 2 To Ws.Range("A" & Rows.Count).End(xlUp).Row
          .AddItem Ws.Range("A" & J)
        Next J
      End With
     
     
     
    End Sub
    Ce code m'aura fillé du fil a retordre ^^, surtout que c'est pas ma formation à la base =). Mais au tout cas merci à votre communauté pour l'aide apporté.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 04/08/2017, 07h13
  2. dessiner une ligne avec des point de coordonnées doubles
    Par tanguy.L dans le forum Débuter
    Réponses: 2
    Dernier message: 11/11/2008, 23h16
  3. Compléter une ligne avec des petits points "à la word"
    Par polemoss dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 22/05/2007, 11h38
  4. Modifier une ligne avec layout:collection
    Par imane_bennouna dans le forum Struts 1
    Réponses: 3
    Dernier message: 07/05/2007, 14h47
  5. [VB6] Scrollbar dans une frame avec des textbox
    Par bb62 dans le forum VB 6 et antérieur
    Réponses: 44
    Dernier message: 01/03/2006, 08h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo