2017-06-14 150 views
0

我正在嘗試使組合框從某個範圍中獲取其值。我只想看到唯一的值,它必須按字母順序排序(不區分大小寫)。對combobox中的數據進行排序不區分大小寫

一切工作正常,除了數據的排序。排序是區分大小寫的,但這不是我想要的。

排序是這樣的:

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 

我希望有人能解決我的問題或者可以給我一個提示。

+1

嘗試'UCASE(ComboBox1.List(B))...'或'選項比較text'也許 –

+0

謝謝,它的工作。如此簡單(一旦你知道如何去做:-))我將我的代碼改爲:如果UCase(ComboBox1.List(b)) AVB

回答

0

嘗試ucase(ComboBox1.List(b))...option compare text perhaps

相關問題