我正在尝试制作一个从范围获取其值的组合框。我只想查看唯一值,并且必须按字母顺序排序(不区分大小写(。
除了数据排序外,一切正常。排序区分大小写,但这不是我想要的。
排序如下:
Door
Room
Window
kitchen
但我想要的方式:
Door
kitchen
Room
Window
您可以在下面找到我的代码:
Dim x, a, b As Long, c As Variant
Dim DataRng As String
Worksheets("House").Activate
'Unique Records
For x = 2 To Cells(Rows.Count, 4).End(xlUp).Row
If WorksheetFunction.CountIf(Range("D2:D" & x), Cells(x, 4)) = 1 Then
ComboBox1.AddItem Cells(x, 4).Value
End If
Next
'Alphabetic Order
For a = 0 To ComboBox1.ListCount - 1
For b = a To ComboBox1.ListCount - 1
If ComboBox1.List(b) < ComboBox1.List(a) Then
c = ComboBox1.List(a)
ComboBox1.List(a) = ComboBox1.List(b)
ComboBox1.List(b) = c
End If
Next
Next
End Sub
我希望有人能解决我的问题或给我一个提示。
尝试ucase(ComboBox1.List(b))...
或option compare text perhaps