-
Aide formulaire Excel
Bonjour,
J'ai créé deux formulaires; le principal (formulaire 1) avec une listbox et 4 textbox, et un autre me servant pour rentrer les données.
Pour l' instant je n'ai réussi qu'à faire ceci:
Formulaire 1
Private Sub UserForm_Initialize()
Worksheets("Data").Visible = False
Worksheets("Data").Activate
Nom.Value = Range("A2").Value
Prénom.Value = Range("B2").Value
Téléphone.Value = Range("F2").Value
Natel.Value = Range("G2").Value
End Sub
Private Sub Ouvre_Click()
Load UserForm2
UserForm2.Show
End Sub
Private Sub Ferme_Click()
Unload UserForm1
End Sub
Le code n'est pas vraiment professionnel (je débute en VBA);
ce que j'aimerai, c'est d'afficher les noms et prénoms (en colonnes)
dans la listbox et ensuite sur double-clic, afficher les champs correspondants dans les textbox.
Pourriez-vous me montrer le code complet? Merci beaucoup.
Traduction
Hello,
I created two forms, the principal (Form 1) with a listbox and 4 textbox, and another I used to return data.
For the moment I managed to do this:
Form 1
Private Sub UserForm_Initialize ()
Worksheets ( "Data"). Visible = False
Worksheets ( "Data"). Activate
Nom.Value = Range ( "A2"). Value
Prénom.Value = Range ( "B2"). Value
Téléphone.Value = Range ( "F2"). Value
Natel.Value = Range ( "G2"). Value
End Sub
Private Sub Ouvre_Click ()
Load UserForm2
UserForm2.Show
End Sub
Private Sub Ferme_Click ()
Unload UserForm1
End Sub
The code is not really professional (I started in VBA);
what I like is to display the names and surnames (in columns)
in the listbox and then double-click and view the corresponding fields
in the textbox.
Could you show me the complete code?
Thank you very much.
-
Try this
[vba]
Option Explicit
Private Sub UserForm_Initialize()
'Uses dynamic range name to get data
ListBox1.List = Range("Names").Resize(, 2).Value
End Sub
Private Sub ListBox1_Click()
Dim c As Range, txt As String
Set c = Range("Names")(ListBox1.ListIndex + 1)
With c
txt = .Offset(, 1) & " " & .Value & vbCr & .Offset(, 2) & vbCr & .Offset(, 3) & vbCr & .Offset(, 4)
End With
TextBox1.Text = txt
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim MyData
Set MyData = New DataObject
MyData.SetText TextBox1.Text
MyData.PutInClipboard
End Sub
[/vba]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules