I have a combobox filled:
01-gennaio
04-aprile
03-marzo
....
How to order items by left 2 digit?
ORDER items in combobox...
-
- Administrator
- Posts: 78608
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: ORDER items in combobox...
Does this do what you want?
Code: Select all
Private Sub CommandButton2_Click()
Dim arr
Dim i As Long
Dim j As Long
Dim tmp
arr = Me.ComboBox1.List
For i = LBound(arr) To UBound(arr) - 1
For j = i + 1 To UBound(arr)
If arr(i, 0) > arr(j, 0) Then
tmp = arr(i, 0)
arr(i, 0) = arr(j, 0)
arr(j, 0) = tmp
End If
Next j
Next i
Me.ComboBox1.List = arr
End Sub
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4368
- Joined: 26 Apr 2010, 17:36
Re: ORDER items in combobox...
Tell me... Have you write this code on fly?HansV wrote:Does this do what you want?
Code: Select all
Private Sub CommandButton2_Click() Dim arr Dim i As Long Dim j As Long Dim tmp arr = Me.ComboBox1.List For i = LBound(arr) To UBound(arr) - 1 For j = i + 1 To UBound(arr) If arr(i, 0) > arr(j, 0) Then tmp = arr(i, 0) arr(i, 0) = arr(j, 0) arr(j, 0) = tmp End If Next j Next i Me.ComboBox1.List = arr End Sub
Last edited by sal21 on 29 Nov 2010, 23:04, edited 1 time in total.
-
- Administrator
- Posts: 78608
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4368
- Joined: 26 Apr 2010, 17:36
Re: ORDER items in combobox...
How many secs have you write this code?HansV wrote:Sorry, what do you mean?
-
- Administrator
- Posts: 78608
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4368
- Joined: 26 Apr 2010, 17:36
Re: ORDER items in combobox...
For alls...HansV wrote:Perhaps 6 minutes...
Hans for me is the only best person i have knowed as professional and as man on line!
I have visited a tons of forums of vb6, vba, access ecc... i know HansV about 6 or 7 years and i'm sure for my thinking.
but the unique "Wizard" is HansV!
Sorry for my bad english but sure the Lounge understand me for that!
Note:
The code to sort the items in combobox work, naturally!
-
- Administrator
- Posts: 78608
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4368
- Joined: 26 Apr 2010, 17:36
Re: ORDER items in combobox...
No prob man!HansV wrote:Thank you!