Diviser en tableau et replace combobox unique

J'ai une dynamic

range("A1:ZZ1") 

Dans cette gamme, chaque cellule sépara les valeurs séparées

 cell("A1")= "City, street, Nr" and etc... 

J'ai deux comboboxes In first, i must select from all cities in range, show only Cities name

 for each cell in range("A1:ZZ1") CitiesArr(x) = split(cell.value,",") x=x+1 next cell me.combobox1.list CitiesArr(1,1) ??? 

In second, i must depending on first selected city, select from all selected cities in range

 If me.combobox1.value="Moscow" then me.combobox2.list = CitiesArr(which contains "Moscow") 

Je confondre comment faire cela ((

 So if cell("A1") ="Moscow, Lenin str.,12" cell("B1") ="Moscow, Centralnaja str.,1" cell("C1") ="Moscow, Lenin str.,98" cell("D1") ="Krim, Chingis str.,23" cell("F1") ="Krim, MUrashev str.,45" .... cell("ZZ1") ="Belostok, Kazik str.,6" in combobox1 I must have UNIQUE (sort Desc) Moscow Krim .... Belostok If I select in combobox1 field Moscow then in combobox2 i must see (sort Desc by Street column) Moscow, Lenin str.,12 Moscow, Centralnaja str.,1 Moscow, Lenin str.,98 .... .... So if cell("A1") ="Moscow, Lenin str.,12" cell("B1") ="Moscow, Centralnaja str.,1" cell("C1") ="Moscow, Lenin str.,98" cell("D1") ="Krim, Chingis str.,23" cell("F1") ="Krim, MUrashev str.,45" .... cell("ZZ1") ="Belostok, Kazik str.,6" in combobox1 I must have UNIQUE (sort Desc) Moscow Krim .... Belostok If I select in combobox1 field Moscow then in combobox2 i must see (sort Desc by Street column) Moscow, Lenin str.,12 Moscow, Centralnaja str.,1 Moscow, Lenin str.,98 .... .... So if cell("A1") ="Moscow, Lenin str.,12" cell("B1") ="Moscow, Centralnaja str.,1" cell("C1") ="Moscow, Lenin str.,98" cell("D1") ="Krim, Chingis str.,23" cell("F1") ="Krim, MUrashev str.,45" .... cell("ZZ1") ="Belostok, Kazik str.,6" in combobox1 I must have UNIQUE (sort Desc) Moscow Krim .... Belostok If I select in combobox1 field Moscow then in combobox2 i must see (sort Desc by Street column) Moscow, Lenin str.,12 Moscow, Centralnaja str.,1 Moscow, Lenin str.,98 .... 

Est-ce ce que vous essayez?

J'ai pris des données d'échantillonnage en seulement 5 cellules pour la démonstration. Veuillez modifier le code, le cas échéant.

 Option Explicit Dim aCell As Range Private Sub UserForm_Initialize() '~~> Change Sheet1 to the relevant sheet name '~~> Change A1:E1 to the relevant range For Each aCell In ThisWorkbook.Sheets("Sheet1").Range("A1:E1") If InStr(1, aCell.Value, ",") Then _ ComboBox1.AddItem Split(aCell.Value, ",")(0) Next aCell '~~> Remove duplicates RemoveDuplicates ComboBox1 End Sub Private Sub ComboBox1_Click() Dim tmpStr As Ssortingng ComboBox2.Clear For Each aCell In ThisWorkbook.Sheets("Sheet1").Range("A1:E1") If InStr(1, aCell.Value, ",") Then _ tmpStr = Split(aCell.Value, ",")(0) If Trim(ComboBox1.Value) = Trim(tmpStr) Then _ ComboBox2.AddItem aCell.Value Next aCell End Sub '~~> Procedure to remove duplicates Private Sub RemoveDuplicates(cmb As ComboBox) Dim a As Integer, b As Integer, c As Integer a = cmb.ListCount - 1 Do While a >= 0 For b = a - 1 To 0 Step -1 If cmb.List(b) = cmb.List(a) Then cmb.RemoveItem b a = a - 1 End If Next b a = a - 1 Loop End Sub 

entrez la description de l'image ici