TonySondergeld
New Member
- Joined
- Jul 11, 2009
- Messages
- 31
Hi All, Just a help required with some code I'm using form this forum and also similar versions found on other site.
Original Post
form here
Now the code does work and on a selection with combo-box 1 will place the range into Combo box 2 in the reverse order (Largest to smallest) However this is on a user form which is displayed vbModeless once it finishes the sub sit there and does nothing which stop user from entry to the worksheet and or code running other that selecting combo box 1. The green run button isn't coming back up on visual basic. You can pause it or stop it though. Try put a if option in a couple different place within the code but either it stop in early and doesn't finish the sort or doesn't do anything. Is there a way of getting it to finish the sort and return the worksheet to user control
Original Post
HTML:
http://www.mrexcel.com/forum/excel-questions/826952-sort-combobox-values-ascending-order-error-code.html
Now the code does work and on a selection with combo-box 1 will place the range into Combo box 2 in the reverse order (Largest to smallest) However this is on a user form which is displayed vbModeless once it finishes the sub sit there and does nothing which stop user from entry to the worksheet and or code running other that selecting combo box 1. The green run button isn't coming back up on visual basic. You can pause it or stop it though. Try put a if option in a couple different place within the code but either it stop in early and doesn't finish the sort or doesn't do anything. Is there a way of getting it to finish the sort and return the worksheet to user control
Code:
Private Sub ComboBox1_Change()
Dim vItems As Variant
Dim vTemp As Variant
Dim i As Long
Dim j As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
With ComboBox2
.Clear
.List = ws.Range("Product1").Value
End With
vItems = Me.ComboBox2.List
For i = LBound(vItems) To UBound(vItems) - 1
For j = i + 1 To UBound(vItems)
If vItems(i, 0) < vItems(j, 0) Then
vTemp = vItems(i, 0)
vItems(i, 0) = vItems(j, 0)
vItems(j, 0) = vTemp
End If
Next j
Next i
Me.ComboBox2.List = vItems
End Sub
Last edited: