PDA

View Full Version : Solved: not case-sensitiv alphabetical order for combobox values



white_flag
05-23-2013, 04:06 AM
Hello I have the following code (it is populating a combobox from a diffrent excel file with some names):

Dim LastRow_clients As Long

Dim i As Long, j As Long, companys As Variant
Dim tmp As Variant


With GetObject(ThisWorkbook.Path & "\Companys.xls")
LastRow_companys = .Sheets(2).Cells.SpecialCells(xlCellTypeLastCell).Row

companys = .Sheets(2).Range("A2", Cells(LastRow_companys, "A").Address).Value
For i = 1 To UBound(companys, 1) - 1
For j = i + 1 To UBound(companys, 1)
If companys(i, 1) > companys(j, 1) Then
tmp = companys(i, 1)
companys(i, 1) = companys(j, 1)
companys(j, 1) = tmp
End If
Next
Next
ComboBox13.List = companys
End With

now the code is sorting in case-sensitiv
AAA
BBB
CCC
DDD
aaa
bbb
ccc
ddd

I like to know How can be done to have:
AAA
aaa
BBB
bbb
CCC
ccc
DDD
ddd

thank you!

JKwan
05-23-2013, 06:53 AM
just change your comparisons to:
If UCase(companys(i, 1)) > UCase(companys(j, 1)) Then

white_flag
05-23-2013, 07:26 AM
yes! ... JKwan, thank you!