Bonjour à toutes et à tous,
Je ne suis pas du tout expert dans le domaine, mais j'ai tendance à bidouiller un petit peu les exemples de codes dont je m'inspire pour que ça fonctionne dans mon cas.
On va donc dire que je suis débrouillard mais sans le côté expert de la chose (et loin de là)
En gros, j'ai deux tableaux sur deux onglets excel différents.
Sur le premier j'ai mon tableau avec un système de recherche de produit qui dépends d'une liste du deuxième onglet.
Dont voici le code : (désolé je ne sais pas comment faire le cadre pour 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 Dim Choix1() Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect([c6:c250], Target) Is Nothing And Target.Count = 1 Then Set f = Sheets("bd") Set rng = f.Range("A2:A" & f.[A65000].End(xlUp).Row) Choix1 = Application.Transpose(rng) Me.ComboBox1.List = Choix1 Me.ComboBox1.Height = Target.Height + 3 Me.ComboBox1.Width = Target.Width Me.ComboBox1.Top = Target.Top Me.ComboBox1.Left = Target.Left Me.ComboBox1 = Target Me.ComboBox1.Visible = True Me.ComboBox1.Activate Else Me.ComboBox1.Visible = False End If End Sub Private Sub ComboBox1_Change() If Me.ComboBox1 <> "" Then mots = Split(Trim(Me.ComboBox1), " ") Tbl = Choix1 For i = LBound(mots) To UBound(mots) Tbl = Filter(Tbl, mots(i), True, vbTextCompare) Next i Me.ComboBox1.List = Tbl Me.ComboBox1.DropDown End If End Sub Private Sub ComboBox1_click() ActiveCell.Value = Me.ComboBox1 End Sub Private Sub ComboBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Me.ComboBox1.List = Choix1 Me.ComboBox1.Activate Me.ComboBox1.DropDown End Sub Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 13 Then ActiveCell.Offset(1).Select End Sub
Cette partie fonctionne et fait ce que je lui demande donc sur ce point c'est nickel (enfin je crois)
Ensuite j'ai voulu faire un userform pour pouvoir rajouter des lignes à cette liste si celle ci ne contenait pas l'article désiré.
En gros dans ma userform j'ai 3 textbox avec champs a renseigner (NOM/Fournisseur/Référence)
Bouton OK, Bouton Annuler.
En théorie mon bouton OK doit incrémenter ma liste en passant automatiquement à la ligne suivante (afin de ne pas écraser des données existantes)
Et mon bouton annuler doit vider les cases des 3 TextBox et fermer l'user form.
Sauf que ca ne se passe pas comme prévu. En fait rien ne se passe et je ne comprends pas pourquoi...
Voici le code de l'Userform que je veux utiliser :
J'espère que ma demande n'est pas trop farfelue et qu'une bonne âme pourra m'expliquer ou la bas blesse.
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 Dim rng As Range Private Sub CommandButton1_Click() UserForm1.Show End Sub Private Sub UserForm_Initialize() InitRange End Sub Private Sub cmd2_Click() Unload UserForm1 End End Sub ' ==== Private Sub cmd1_Click() WriteRecord InitTextBox End Sub Private Sub WriteRecord() With rng .Cells(.Rows.Count + 1, 1) = Me.TextNom .Cells(.Rows.Count + 1, 7) = Me.TextFournisseur .Cells(.Rows.Count + 1, 2) = Me.TextRef End With InitRange ' Recalcul la plage End Sub Private Sub InitRange() Set rng = ThisWorkbook.Worksheets("BD").Range("A1").CurrentRegion End Sub Private Sub InitTextBox() With Me: .TextNom = "": .TextFournisseur = "": .TextRef = "": .TextNom.SetFocus: End With End Sub
Merci d'avance!
Matt
Edit : Merci pour la modification.




Répondre avec citation



Partager