2017-04-25 21 views
0

belwoコーディングの助けを借りて、コンボボックスから重複アイテムを削除できますが、昇順でアイテムを反映していません。私はコンボボックスのすべての項目を昇順に反映したい。 助けてください。あなたは良いスタートがあるんだ何コンボボックスのアイテムを昇順で表示する

ComboBox37.Clear 
With CreateObject("Scripting.Dictionary") 
    For Each rCell In wksSource.Range("M6", wksSource.Cells(Rows.Count, "M").End(xlUp)) 
      If Not .exists(rCell.Value) Then 
       .Add rCell.Value, Nothing 
      End If 
    Next rCell 
    ComboBox37.List = .keys 
End With 

答えて

0

、あなただけの彼らはすべてロードしていたら、すぐにそれらをソートする必要があります。

ComboBox37.Clear 
With CreateObject("Scripting.Dictionary") 
    For Each rCell In wksSource.Range("M6", wksSource.Cells(Rows.Count, "M").End(xlUp)) 
      If Not .exists(rCell.Value) Then 
       .Add rCell.Value, Nothing 
      End If 
    Next rCell 
    ComboBox37.List = .keys 
End With 

With ComboBox37 
    For a = 0 To .ListCount - 1 
     For b = a To .ListCount - 1 
      If .List(b) < .List(a) Then 
       c = .List(a) 
       .List(a) = .List(b) 
       .List(b) = c 
      End If 
     Next 
    Next 
End With 
0

ArrayListは、このようなケースのための別の有用なデータ構造であり、これは、Containsメソッド(Dictionary.Existsメソッドと同様)およびSortメソッドをサポートしています。これは、ワークシートデータ自体を操作(ソート)したくない場合に特に便利です。

Dim list As Object 
Set list = CreateObject("System.Collections.ArrayList") 
Set rng = wksSource.Range("M6", wksSource.Cells(Rows.Count, "M").End(xlUp)) 
ComboBox37.Clear 
For Each rCell In rng.Cells 
    If Not list.Contains(rCell.Value) Then list.Add (rCell.Value) 
Next rCell 
Dim v 
'Sort the ArrayList object: 
list.Sort 
ComboBox37.list = list.ToArray() 
Set list = Nothing 
関連する問題