Lier des list box
Bonjour à Tous,
Dans un Userform, je possède 4 combobox (comboboxVille1... jusqu'à comboboxVille4), les combobox inscrivent la donnée dans la colonne G, N, U et AB respectivement.
Pouvez vous me dire comment faire pour que dans la liste déroulante du comboboxVille1 apparaissent toutes les villes enregistrées dans les colonnes G, N, U et AB ? et ainsi de suite pour les autres combobox ?
Merci d'avance
Voici les codes que j'ai déjà écrit :
Private Sub ComboBoxVille1_Change()
ComboBoxVille1 = UCase(ComboBoxVille1)
End SubPrivate Sub UserForm_Initialize()
Dim num As Integer
num = Range("A65536").End(xlUp).Row
If Right(Range("A" & num), 4) < 9 Then
TextBox1 = "Equipe000" & Right(Range("A" & num), 4) + 1
Else
If Right(Range("A" & num), 4) < 99 Then
TextBox1 = "Equipe00" & Right(Range("A" & num), 4) + 1
Else
If Right(Range("A" & num), 4) < 999 Then
TextBox1 = "Equipe0" & Right(Range("A" & num), 4) + 1
Else
TextBox1 = "Equipe" & Right(Range("A" & num - 1), 4) + 1
End If
End If
End If
Set F = Sheets("Equipes")
Set MonDico = CreateObject("Scripting.Dictionary")
For Each c In Range(F.[G7], F.[G65000].End(xlUp))
If c.Value <> "" Then MonDico.Item(c.Value) = c.Value
Next c
'Me.ComboBoxVille1.List = MonDico.items
'--avec tri
Temp = MonDico.items
Call Tri(Temp, LBound(Temp), UBound(Temp))
Me.ComboBoxVille1.List = Temp
Set MonDico = CreateObject("Scripting.Dictionary")
For Each c In Range(F.[N7], F.[N65000].End(xlUp))
If c.Value <> "" Then MonDico.Item(c.Value) = c.Value
Next c
'Me.ComboBoxVille2.List = MonDico.items
'--avec tri
Temp = MonDico.items
Call Tri(Temp, LBound(Temp), UBound(Temp))
Me.ComboBoxVille2.List = Temp
Set MonDico = CreateObject("Scripting.Dictionary")
For Each c In Range(F.[U7], F.[U65000].End(xlUp))
If c.Value <> "" Then MonDico.Item(c.Value) = c.Value
Next c
'Me.ComboBoxVille3.List = MonDico.items
'--avec tri
Temp = MonDico.items
Call Tri(Temp, LBound(Temp), UBound(Temp))
Me.ComboBoxVille3.List = Temp
Set MonDico = CreateObject("Scripting.Dictionary")
For Each c In Range(F.[AB7], F.[AB65000].End(xlUp))
If c.Value <> "" Then MonDico.Item(c.Value) = c.Value
Next c
'Me.ComboBoxVille4.List = MonDico.items
'--avec tri
Temp = MonDico.items
Call Tri(Temp, LBound(Temp), UBound(Temp))
Me.ComboBoxVille4.List = Temp
End SubPrivate Sub CmdValider_Click()
Dim num As Integer
num = Range("A65536").End(xlUp).Row + 1
'Mise en place des valeurs saisies
Range("A" & num) = TextBox1
Range("A" & num).Borders.Weight = xlThin
Range("B" & num).Value = TextBoxNomEquipe
Range("B" & num).Borders.Weight = xlThin
Range("B" & num).Interior.ColorIndex = 3
Range("C" & num).Value = TextBoxNom1
Range("C" & num).Borders.Weight = xlThin
Range("C" & num).Interior.ColorIndex = 37
Range("D" & num).Value = TextBoxPrenom1
Range("D" & num).Borders.Weight = xlThin
Range("D" & num).Interior.ColorIndex = 37
Range("E" & num).Value = TextBoxAdresse1
Range("E" & num).Borders.Weight = xlThin
Range("E" & num).Interior.ColorIndex = 37
Range("F" & num).Value = TextBoxCodePostal1
Range("F" & num).Borders.Weight = xlThin
Range("F" & num).Interior.ColorIndex = 37
Range("G" & num).Value = ComboBoxVille1
Range("G" & num).Borders.Weight = xlThin
Range("G" & num).Interior.ColorIndex = 37
Range("H" & num).Value = TextBoxTelephone1
Range("H" & num).Borders.Weight = xlThin
Range("H" & num).Interior.ColorIndex = 37
Range("I" & num).Value = TextBoxMail1
Range("I" & num).Borders.Weight = xlThin
Range("I" & num).Interior.ColorIndex = 37
Range("J" & num).Value = TextBoxNom2
Range("J" & num).Borders.Weight = xlThin
Range("J" & num).Interior.ColorIndex = 44
Range("K" & num).Value = TextBoxPrenom2
Range("K" & num).Borders.Weight = xlThin
Range("K" & num).Interior.ColorIndex = 44
Range("L" & num).Value = TextBoxAdresse2
Range("L" & num).Borders.Weight = xlThin
Range("L" & num).Interior.ColorIndex = 44
Range("M" & num).Value = TextBoxCodePostal2
Range("M" & num).Borders.Weight = xlThin
Range("M" & num).Interior.ColorIndex = 44
Range("N" & num).Value = ComboBoxVille2
Range("N" & num).Borders.Weight = xlThin
Range("N" & num).Interior.ColorIndex = 44
Range("O" & num).Value = TextBoxTelephone2
Range("O" & num).Borders.Weight = xlThin
Range("O" & num).Interior.ColorIndex = 44
Range("P" & num).Value = TextBoxMail2
Range("P" & num).Borders.Weight = xlThin
Range("P" & num).Interior.ColorIndex = 44
Range("Q" & num).Value = TextBoxNom3
Range("Q" & num).Borders.Weight = xlThin
Range("Q" & num).Interior.ColorIndex = 37
Range("R" & num).Value = TextBoxPrenom3
Range("R" & num).Borders.Weight = xlThin
Range("R" & num).Interior.ColorIndex = 37
Range("S" & num).Value = TextBoxAdresse3
Range("S" & num).Borders.Weight = xlThin
Range("S" & num).Interior.ColorIndex = 37
Range("T" & num).Value = TextBoxCodePostal3
Range("T" & num).Borders.Weight = xlThin
Range("T" & num).Interior.ColorIndex = 37
Range("U" & num).Value = ComboBoxVille3
Range("U" & num).Borders.Weight = xlThin
Range("U" & num).Interior.ColorIndex = 37
Range("V" & num).Value = TextBoxTelephone3
Range("V" & num).Borders.Weight = xlThin
Range("V" & num).Interior.ColorIndex = 37
Range("W" & num).Value = TextBoxMail3
Range("W" & num).Borders.Weight = xlThin
Range("W" & num).Interior.ColorIndex = 37
Range("X" & num).Value = TextBoxNom4
Range("X" & num).Borders.Weight = xlThin
Range("X" & num).Interior.ColorIndex = 44
Range("Y" & num).Value = TextBoxPrenom4
Range("Y" & num).Borders.Weight = xlThin
Range("Y" & num).Interior.ColorIndex = 44
Range("Z" & num).Value = TextBoxAdresse4
Range("Z" & num).Borders.Weight = xlThin
Range("Z" & num).Interior.ColorIndex = 44
Range("AA" & num).Value = TextBoxCodePostal4
Range("AA" & num).Borders.Weight = xlThin
Range("AA" & num).Interior.ColorIndex = 44
Range("AB" & num).Value = ComboBoxVille4
Range("AB" & num).Borders.Weight = xlThin
Range("AB" & num).Interior.ColorIndex = 44
Range("AC" & num).Value = TextBoxTelephone4
Range("AC" & num).Borders.Weight = xlThin
Range("AC" & num).Interior.ColorIndex = 44
Range("AD" & num).Value = TextBoxMail4
Range("AD" & num).Borders.Weight = xlThin
Range("AD" & num).Interior.ColorIndex = 44
Unload Me 'vide et ferme l'UserForm
'bouton fermer
End SubBonjour à Tous,
De l'aide !!! Merci
Bonjour
Aides toi et le ciel t'aidera : Lis "A lire avant de poster" (article 6)
Joins ton fichier est une première étape, et la suivante est de bien expliquer ce que tu veux
Moi je comprends que tes 4 ComboBox (ListBox d'après le titre) doivent avoir les mêmes informations, ce qui me parait bizarre
Bonjour Banzai64,
Voici mon fichier. Tu comprendras aisément que je suis novice !!! En fait je souhaite que mes 4 combobox aient la même source, ainsi donc dans la liste déroulante doivent apparaitre toutes les villes entrées (que ce soit par le comboboxVille1, 2 ou 3 ou 4)
Merci d'avance pour ton aide
Bonjour
youlig a écrit :je suis novice
Tout le monde à commencé un jour
A voir si c'est ce que tu veux
Super, Merci Banzai64. C'est exactement ce que je cherchais à faire depuis plusieurs jours.
Merci aussi pour l'encouragement. Cela me plait beaucoup de travailler sur VBA et j'en passe des heures.
A plus tard peut être pour d'autres questions et bonne journée.
Youlig