fredzertya
XLDnaute Nouveau
Bonjour,
Je suis débutant en VBA, et me trouve devant un problème, sur une feuille il y a plusieurs combobox l'idée et d'avoir une saisie intuitif sur les combox, j'ai un code qui fonctionne bien sur la combobox1, que je voudrais reproduire légèrement modifier pour les autres combobox de la feuille, et là problème, je ne sais pas comment faire, pour avoir plusieurs code sur la même feuille.
Merci par avance.
____________________________________________________________________________________________________
1er code sur la feuille
Dim a()
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect([C14:C14], Target) Is Nothing And Target.Count = 1 Then
Set f = Sheets("BD")
a = Application.Transpose(f.Range("L1:L" & f.[A65000].End(xlUp).Row))
Me.ComboBox1.List = a
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 <> "" And IsError(Application.Match(Me.ComboBox1, a, 0)) Then
Me.ComboBox1.List = Filter(a, Me.ComboBox1.Text, True, vbTextCompare)
Me.ComboBox1.DropDown
End If
ActiveCell.Value = Me.ComboBox1
End Sub
Private Sub ComboBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.ComboBox1.List = a
Me.ComboBox1.Activate
Me.ComboBox1.DropDown
End Sub
___________________________________________________________________________________________________
2eme code sur la même feuille
Dim a()
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect([C16:C16], Target) Is Nothing And Target.Count = 1 Then
Set f = Sheets("BDD")
a = Application.Transpose(f.Range("B5:B" & f.[A65000].End(xlUp).Row))
Me.ComboBox2.List = a
Me.ComboBox2.Height = Target.Height + 3
Me.ComboBox2.Width = Target.Width
Me.ComboBox2.Top = Target.Top
Me.ComboBox2.Left = Target.Left
Me.ComboBox2 = Target
Me.ComboBox2.Visible = True
Me.ComboBox2.Activate
Else
Me.ComboBox2.Visible = False
End If
End Sub
Private Sub ComboBox2_Change()
If Me.ComboBox2 <> "" And IsError(Application.Match(Me.ComboBox2, a, 0)) Then
Me.ComboBox2.List = Filter(a, Me.ComboBox2.Text, True, vbTextCompare)
Me.ComboBox2.DropDown
End If
ActiveCell.Value = Me.ComboBox2
End Sub
Private Sub ComboBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.ComboBox2.List = a
Me.ComboBox2.Activate
Me.ComboBox2.DropDown
End Sub
Je suis débutant en VBA, et me trouve devant un problème, sur une feuille il y a plusieurs combobox l'idée et d'avoir une saisie intuitif sur les combox, j'ai un code qui fonctionne bien sur la combobox1, que je voudrais reproduire légèrement modifier pour les autres combobox de la feuille, et là problème, je ne sais pas comment faire, pour avoir plusieurs code sur la même feuille.
Merci par avance.
____________________________________________________________________________________________________
1er code sur la feuille
Dim a()
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect([C14:C14], Target) Is Nothing And Target.Count = 1 Then
Set f = Sheets("BD")
a = Application.Transpose(f.Range("L1:L" & f.[A65000].End(xlUp).Row))
Me.ComboBox1.List = a
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 <> "" And IsError(Application.Match(Me.ComboBox1, a, 0)) Then
Me.ComboBox1.List = Filter(a, Me.ComboBox1.Text, True, vbTextCompare)
Me.ComboBox1.DropDown
End If
ActiveCell.Value = Me.ComboBox1
End Sub
Private Sub ComboBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.ComboBox1.List = a
Me.ComboBox1.Activate
Me.ComboBox1.DropDown
End Sub
___________________________________________________________________________________________________
2eme code sur la même feuille
Dim a()
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect([C16:C16], Target) Is Nothing And Target.Count = 1 Then
Set f = Sheets("BDD")
a = Application.Transpose(f.Range("B5:B" & f.[A65000].End(xlUp).Row))
Me.ComboBox2.List = a
Me.ComboBox2.Height = Target.Height + 3
Me.ComboBox2.Width = Target.Width
Me.ComboBox2.Top = Target.Top
Me.ComboBox2.Left = Target.Left
Me.ComboBox2 = Target
Me.ComboBox2.Visible = True
Me.ComboBox2.Activate
Else
Me.ComboBox2.Visible = False
End If
End Sub
Private Sub ComboBox2_Change()
If Me.ComboBox2 <> "" And IsError(Application.Match(Me.ComboBox2, a, 0)) Then
Me.ComboBox2.List = Filter(a, Me.ComboBox2.Text, True, vbTextCompare)
Me.ComboBox2.DropDown
End If
ActiveCell.Value = Me.ComboBox2
End Sub
Private Sub ComboBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.ComboBox2.List = a
Me.ComboBox2.Activate
Me.ComboBox2.DropDown
End Sub
Dernière édition: