ORDER items in combobox...

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

ORDER items in combobox...

Post by sal21 »

I have a combobox filled:

01-gennaio
04-aprile
03-marzo
....
How to order items by left 2 digit?

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ORDER items in combobox...

Post by HansV »

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

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: ORDER items in combobox...

Post by sal21 »

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
Tell me... Have you write this code on fly? :scratch:
Last edited by sal21 on 29 Nov 2010, 23:04, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ORDER items in combobox...

Post by HansV »

Sorry, what do you mean?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: ORDER items in combobox...

Post by sal21 »

HansV wrote:Sorry, what do you mean?
How many secs have you write this code?

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ORDER items in combobox...

Post by HansV »

Perhaps 6 minutes...
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: ORDER items in combobox...

Post by sal21 »

HansV wrote:Perhaps 6 minutes...
For alls...
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! :fanfare: :fanfare: :fanfare: :fanfare: :fanfare:

Note:
The code to sort the items in combobox work, naturally!
:thankyou:

User avatar
HansV
Administrator
Posts: 78608
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: ORDER items in combobox...

Post by HansV »

Thank you!
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: ORDER items in combobox...

Post by sal21 »

HansV wrote:Thank you!
No prob man!