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 :

Modification d'un code VBA [XL-2013]


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Mars 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France

    Informations professionnelles :
    Activité : Chargé d'affaire

    Informations forums :
    Inscription : Mars 2014
    Messages : 5
    Par défaut Modification d'un code VBA
    Bonjour
    J'ai un formulaire qui fonctionne très mais j'aimerai lui apporter un modification, j'aimerai si possible supprimer la listBox qu'il y a dans le UsF_Recherche et lorsque je rentre un nom de département soit manuellement soit automatiquement dans la TxtB_Recherche et que je clique a l'intérieur sa m'ouvre UsF_Resultat sinon le principe et excellent.

    Je Vous remercie d'avance et te souhaite une bonne soirée
    Mon 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
    UserForm2.Show
    End Sub
     
    Private Sub LstB_Recherche_Click()
    With UsF_Recherche
      With .LstB_Recherche
     Lgn = .List(.ListIndex, 1)
     
      End With
    Unload Me
    End With
    With UsF_Resultat
     With .TxtB_Departement
          .Value = ""
          .Text = Tab_Source(Lgn, 1)
     End With
     With .TxtB_Chef_Lieux
          .Value = ""
          .Text = Tab_Source(Lgn, 2)
     End With
     
     With .TxtB_Arrondissement
          .Value = ""
          .Text = Tab_Source(Lgn, 3)
     End With
     With .TxtB_Cantons
          .Value = ""
           .Text = Tab_Source(Lgn, 4)
     End With
     With .TxtB_Communes
          .Value = ""
          .Text = Tab_Source(Lgn, 5)
     End With
     With .TxtB_Populations
          .Value = ""
          .Text = Tab_Source(Lgn, 6)
     End With
     With .TxtB_Densite
          .Value = ""
          .Text = Tab_Source(Lgn, 7)
     End With
     With .TxtB_Superficie
          .Value = ""
          .Text = Tab_Source(Lgn, 8)
     End With
     .Show
    End With
    End Sub
     
    Private Sub TxtB_Recherche_Change()
    x = 0 'on initialise à 0
    Str_Search = "" 'on vide la variable
    Erase Tab_Recherche 'on vide le tableau
    With UsF_Recherche 'avec le Userform
         .LstB_Recherche.Clear 'on efface la ListBox
     Str_Search = UCase(.TxtB_Recherche.Text) 'on récupére la valeur du TextBox(en minuscule)
      If Str_Search = "" Then Exit Sub 'si la variable texte est vide on quitte
    For Lgn = 1 To UBound(Tab_Source, 1) 'pour chaque ligne du tableau source
      If UCase(Tab_Source(Lgn, 1)) Like UCase(Str_Search) & "*" Then ' si correspondance
        ReDim Preserve Tab_Recherche(2, x) 'on redimmensionne le tableau Recherche
           Tab_Recherche(0, x) = Tab_Source(Lgn, 1) 'on entre la valeur de la premiere colonne du tableau source
           Tab_Recherche(1, x) = Lgn 'on entre la reference a la ligne ou se trouve la valeur trouvee
           x = x + 1 'on incremente
      End If
    Next Lgn 'autre ligne
    End With
    If x = 0 Then Exit Sub 'si pas de resultat on quitte
    UsF_Recherche.LstB_Recherche.Column = Tab_Recherche()
    End Sub
     
    Private Sub UserForm_Initialize()
    Set Ws_Source = Worksheets("Départements") 'on initialise la variable feuille
    With Ws_Source 'avec cette feuille
        DerLgn = .Cells(.Rows.Count, 3).End(xlUp).Row 'on determine la derniere ligne non vide de la colonne 3(C)
    Tab_Source = .Range(.Cells(1, 3), .Cells(DerLgn, 10)).Value 'on récupé"re dans le tab_Source les valeur de la plage ainsi définie
    End With
    With UsF_Recherche 'avec le Userform
      With .LstB_Recherche 'avec la ListBox
           .ColumnCount = 2 'on formate a 2 colonne
           .ColumnWidths = "213;0" 'une visible(Departement) l'autre non(reference a la ligne dans le tableau)
      End With
    End With
    End Sub
    Je vous joins mon exemple qui seras plus explicite.

    Merci D'avance

    Cordialement

    Max
    Fichiers attachés Fichiers attachés

  2. #2
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Septembre 2011
    Messages
    8 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Septembre 2011
    Messages : 8 208
    Par défaut
    Bonjour,

    Pourquoi conserver UsF_Recherche ?

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Mars 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France

    Informations professionnelles :
    Activité : Chargé d'affaire

    Informations forums :
    Inscription : Mars 2014
    Messages : 5
    Par défaut
    Bonjour Daniel

    Est merci d'avoir répond.

    Pourquoi conserver UsF_Recherche ?
    Parce que a l'origine il y a une carte de france créer en Chappe qui ouvre un formulaire qui se nome UsF_Recherche et dans le textbox nommer "TxtB_Recherche" il y a un nom de département et j'aimerai que lorsque je clique dans le textBox "TxtB_Recherche" il m'ouvre le'UserForm UsF_Resultat avec tous les textbox rempli a l'aide de la feuille nommer Département.

    J'espère avoir était assez explicite sinon je me tiens a ta disposition

    Cordialement

    Max

  4. #4
    Expert confirmé
    Homme Profil pro
    aucune
    Inscrit en
    Septembre 2011
    Messages
    8 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : aucune

    Informations forums :
    Inscription : Septembre 2011
    Messages : 8 208
    Par défaut
    Une fois le textbox rempli, il faut faire un double-clic dedans. Voici le code (j'ai limité les modifs au minimum) :

    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
    'Appel par textbox
    Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
     
    UserForm2.Show
    End Sub
     
    Private Sub LstB_Recherche_Click()
    With UsF_Recherche
      With .LstB_Recherche
     Lgn = .List(.ListIndex, 1)
     
      End With
    Unload Me
    End With
    With UsF_Resultat
     With .TxtB_Departement
          .Value = ""
          .Text = Tab_Source(Lgn, 1)
     End With
     With .TxtB_Chef_Lieux
          .Value = ""
          .Text = Tab_Source(Lgn, 2)
     End With
     
     With .TxtB_Arrondissement
          .Value = ""
          .Text = Tab_Source(Lgn, 3)
     End With
     With .TxtB_Cantons
          .Value = ""
           .Text = Tab_Source(Lgn, 4)
     End With
     With .TxtB_Communes
          .Value = ""
          .Text = Tab_Source(Lgn, 5)
     End With
     With .TxtB_Populations
          .Value = ""
          .Text = Tab_Source(Lgn, 6)
     End With
     With .TxtB_Densite
          .Value = ""
          .Text = Tab_Source(Lgn, 7)
     End With
     With .TxtB_Superficie
          .Value = ""
          .Text = Tab_Source(Lgn, 8)
     End With
     .Show
    End With
    End Sub
     
     
    Private Sub TxtB_Recherche_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
        Lgn = Application.Match(Me.TxtB_Recherche, [Départements!C:C], 0)
        Unload UsF_Recherche
        If IsNumeric(Lgn) Then
            With UsF_Resultat
             With .TxtB_Departement
                  .Value = ""
                  .Text = Sheets("Départements").Cells(Lgn, 3)
             End With
             With .TxtB_Chef_Lieux
                  .Value = ""
                  .Text = Sheets("Départements").Cells(Lgn, 4)
             End With
     
             With .TxtB_Arrondissement
                  .Value = ""
                  .Text = Sheets("Départements").Cells(Lgn, 5)
             End With
             With .TxtB_Cantons
                  .Value = ""
                   .Text = Sheets("Départements").Cells(Lgn, 6)
             End With
             With .TxtB_Communes
                  .Value = ""
                  .Text = Sheets("Départements").Cells(Lgn, 7)
             End With
             With .TxtB_Populations
                  .Value = ""
                  .Text = Sheets("Départements").Cells(Lgn, 8)
             End With
             With .TxtB_Densite
                  .Value = ""
                  .Text = Sheets("Départements").Cells(Lgn, 9)
             End With
             With .TxtB_Superficie
                  .Value = ""
                  .Text = Sheets("Départements").Cells(Lgn, 10)
             End With
             .Show
            End With
        End If
    End Sub
    maval18 textbox-pour-ouvrir-une-fiche-de-renseignementdept.zip

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Mars 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France

    Informations professionnelles :
    Activité : Chargé d'affaire

    Informations forums :
    Inscription : Mars 2014
    Messages : 5
    Par défaut
    RE,

    Je te remercie Nickel

    Bonne soirée

    Max

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

Discussions similaires

  1. [XL-2010] Aide pour modification d'un code VBA (Fonction Ping sous Excel)
    Par osiris13010 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 08/07/2012, 14h16
  2. Code VBA modification du type de graphique
    Par Tifriis dans le forum VBA Access
    Réponses: 7
    Dernier message: 30/11/2010, 10h06
  3. Détecter une modification du code VBA
    Par elmagnifico dans le forum Excel
    Réponses: 4
    Dernier message: 26/08/2009, 18h53
  4. Modification d'un code VBA
    Par marcuswillbe dans le forum Excel
    Réponses: 2
    Dernier message: 11/02/2009, 15h39
  5. Bug Excel lors d'une tentative de modif de code VBA
    Par aerodynamique dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 27/11/2007, 11h28

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