【问题标题】:Sorting data in combobox case insensitive在组合框中对数据进行排序,不区分大小写
【发布时间】:2017-11-16 18:35:21
【问题描述】:

我正在尝试制作一个从某个范围内获取其值的组合框。我只想查看唯一值,并且必须按字母顺序排序(不区分大小写)。

除数据排序外,一切正常。排序区分大小写,但这不是我想要的。

排序是这样的:

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
  • 谢谢,它成功了。如此简单(一旦你知道怎么做 :-))我将代码更改为: If UCase(ComboBox1.List(b))

标签: excel vba sorting combobox


【解决方案1】:

试试ucase(ComboBox1.List(b))...option compare text perhaps

【讨论】:

    猜你喜欢
    • 2011-01-30
    • 1970-01-01
    • 2023-03-29
    • 2013-04-17
    • 2018-01-11
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多