+ Reply to Thread
Results 1 to 5 of 5

Excel 2007 sort combobox

  1. #1
    Registered User
    Join Date
    05-19-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Post Excel 2007 sort combobox

    Hi everyone, this is my first post, and I am NOT a proficient VBA programmer. For some of you this might be easy, but after 2 days, it is driving me nuts.

    I have a combobox which is populated with folder names,, the folder names are month and year. eg Apr 2013, this works fine, no problems. The problem is, in the combobox list the months are in alphabetical order, I would like to sort them so that they run from Jan 2013 to Dec 2013.

    All help appreciated, but PLEASE keep it relevant.

    My code:

    Private Sub CommandButton1_Click()
    Dim name


    Me.ComboBox2.Clear
    For Each name In ListDirectory(Path:="C:\Users\Laurie\Documents\Pai Hotel\Log\Daily Log - Year 2013\", AttrInclude:=vbDirectory, AttrExclude:=vbSystem Or vbHidden)
    If name Like "Jan*" Or name Like "Feb*" Or name Like "Mar*" Or name Like "Apr*" Or name Like "May*" Or name Like "Jun*" _
    Or name Like "Jul*" Or name Like "Aug*" Or name Like "Sep*" Or name Like "Oct*" Or name Like "Nov*" Or name Like "Dec*" Then

    Me.ComboBox2.AddItem name
    End If
    Next name

    End Sub
    Last edited by LaurieH; 05-20-2013 at 05:06 AM.

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Excel 2007 sort combobox

    Hi LaurieH,
    maybe something like this
    Please Login or Register  to view this content.

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Excel 2007 sort combobox

    You can fill the comobox with montnames:

    Please Login or Register  to view this content.
    After selection you can open the file using:

    Please Login or Register  to view this content.
    Last edited by snb; 05-19-2013 at 08:56 AM.



  4. #4
    Registered User
    Join Date
    05-19-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Excel 2007 sort combobox

    snb, thanks for you quick reply, the first part you supplied isn't quite what I wanted, BUT, the second part I can use, thanks again.

  5. #5
    Registered User
    Join Date
    05-19-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Excel 2007 sort combobox

    nlerm, thanks for your very quick reply, your code is exactly what I needed, I have a lot to learn .

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1