Hi,
I have a combo box on my spreadsheet that I use to return a value for a bunch of vlookups on the sheet. I was trying to sort the values in the combo box. I found some posts in this forum, and used code found in one of them. It worked great... except, I have 2 columns in my combo box and right now one of them is sorted by not the other, so the data displayed in the combo box is now not aligned properly.
Here's a copy of the modified code. Both of the columns to be displayed in the combo box are alphabetical. Please help!!! Thanks.
Private Sub ComboBox1_GotFocus()
ComboBox1.Clear
ComboBox1.List = Worksheets("Data1").Range("Company_Name").Value
ComboBox1.BoundColumn = 1
ComboBox1.ColumnCount = 2
Dim unsorted As Boolean, i As Integer, temp As Variant
unsorted = True
Do
unsorted = False
For i = 0 To UBound(ComboBox1.List) - 1
If ComboBox1.List(i) > ComboBox1.List(i + 1) Then
temp = ComboBox1.List(i)
ComboBox1.List(i) = ComboBox1.List(i + 1)
ComboBox1.List(i + 1) = temp
unsorted = True
Exit For
End If
Next i
Loop While unsorted = True
End Sub
I have a combo box on my spreadsheet that I use to return a value for a bunch of vlookups on the sheet. I was trying to sort the values in the combo box. I found some posts in this forum, and used code found in one of them. It worked great... except, I have 2 columns in my combo box and right now one of them is sorted by not the other, so the data displayed in the combo box is now not aligned properly.
Here's a copy of the modified code. Both of the columns to be displayed in the combo box are alphabetical. Please help!!! Thanks.
Private Sub ComboBox1_GotFocus()
ComboBox1.Clear
ComboBox1.List = Worksheets("Data1").Range("Company_Name").Value
ComboBox1.BoundColumn = 1
ComboBox1.ColumnCount = 2
Dim unsorted As Boolean, i As Integer, temp As Variant
unsorted = True
Do
unsorted = False
For i = 0 To UBound(ComboBox1.List) - 1
If ComboBox1.List(i) > ComboBox1.List(i + 1) Then
temp = ComboBox1.List(i)
ComboBox1.List(i) = ComboBox1.List(i + 1)
ComboBox1.List(i + 1) = temp
unsorted = True
Exit For
End If
Next i
Loop While unsorted = True
End Sub