Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Nov 2001
    Location
    London
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Combo boxes (97)

    I have a combo box with 24 values in it - they are each month of this year and each month of last year ie. Jan 2001, Feb 2001, Mar 2001 ........ Dec 2002
    The values are in correct order. When the user clicks on the drop arrow to activate the combo box, is there any way to have the current month appear at the top of the list, but still have the months in the correct order. The previous months would be above the current months, but you would have to use the scroll bar to see what they are.

    Any suggestions welcome

    Thanks

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Combo boxes (97)

    Are you using a UserForm or an on sheet combobox ?

    How is the combobox list populated and is it populated with actual dates or just text representing each month ?

    Andrew C

  3. #3
    New Lounger
    Join Date
    Nov 2001
    Location
    London
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combo boxes (97)

    I am using a combo box on a userform and this is the code I am using to populate the combo box

    Private Sub UserForm_Initialize()
    Dim intMonth As Integer
    With Me.ComboBox1
    Do Until intMonth >= 24
    .AddItem Format(DateAdd("m", intMonth, #1/1/01#), "mmm yy")
    intMonth = intMonth + 1
    Loop
    End With
    End Sub

    Any ideas?

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Combo boxes (97)

    Try adding the line in red below to your code

    Private Sub UserForm_Initialize()
    Dim intMonth As Integer
    With Me.ComboBox1
    Do Until intMonth >= 24
    AddItem Format(DateAdd("m", intMonth, #1/1/01#), "mmm yy")
    intMonth = intMonth + 1
    Loop
    End With
    <font color=red>Me.ComboBox1.ListIndex = DateDiff("m", #1/1/01#, Now())</font color=red>
    End Sub

    Andrew C

  5. #5
    New Lounger
    Join Date
    Nov 2001
    Location
    London
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combo boxes (97)

    Thanks Andrew, that works fine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •