Plusieurs "Saisie Dynamique" dans une feuille

Bonjour à tous !

Je réalise un fichier Excel avec une saisie dynamique (type google).

J'arrive à le faire sur une feuille pour une liste de données.

Par contre j'aimerais le faire pour 3 autres tableaux sur la même feuille et avec 3 listes différents.

Je recopie mon code qui fonctionne, en changeant "ComboBox1" par "ComboBox2" et a par b. Et ce la m'indique "Nom Ambigue".

Après quelques recherches j'ai vu que c'est le "Worksheet SelectionChange" qui ne fonctionne pas, il ne peut pas être 2 fois dans un code.

Il faudrait donc fusionner tout ce code mais j'ai aucune idée de la procédure ... J'ai essayé "Elseif" sans succès.

Pouvez-vous m'éclairer?

Je vous remercie par avance

Bonjour,

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

  If Not Intersect([A15:A25], Target) Is Nothing And Target.Count = 1 Then
    Set f = Sheets("Articles")
    a = Application.Transpose(f.Range("A2:A" & f.[B65000].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

  If Not Intersect([G15:G25], Target) Is Nothing And Target.Count = 1 Then
    Set f = Sheets("Articles")
    b = Application.Transpose(f.Range("C2:C" & f.[B65000].End(xlUp).Row))
    Me.ComboBox2.List = b
    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

Il fallait aussi changer a en b

Bonjour ABCIVEN, bonjour le forum,

Peut-être comme ça :

Private f As Worksheet

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim TEST As Boolean
Dim V As Variant

Set f = Sheets("Articles")
If Not Intersect([A15:A25], Target) Is Nothing And Target.Count = 1 Then
    TEST = True: V = Application.Transpose(f.Range("A2:A" & f.[B65000].End(xlUp).Row))
End If
If Not Intersect([G15:G25], Target) Is Nothing And Target.Count = 1 Then
    TEST = True: V = Application.Transpose(f.Range("C2:C" & f.[B65000].End(xlUp).Row))
End If
If TEST = True Then
  Me.ComboBox1.List = V
  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

[Édition]

Bonjour Steelson, nos post se sont croisés...

Merci à vous deux !

Cela fonctionne

Rechercher des sujets similaires à "saisie dynamique feuille"