# Descending order in Userform ComboBox?



## jmpatrick (Dec 16, 2022)

Happy Friday!

Here's my code that lists folders in a UserForm ComboBox.  This works fine but the results are oldest first (ascending).  Is it possible to make the order descending?


```
Dim fso As Object
    Dim MySubFolder As Object
    Dim MyPath  As String
    
    MyPath = "\\GLC-SERVER\Pulte\Z_Pulte Master Archive\"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
       
    For Each MySubFolder In fso.GetFolder(MyPath).SubFolders
        Archive_Open_Year.AddItem MySubFolder.Name
    Next MySubFolder
```


----------



## DanteAmor (Dec 16, 2022)

The order is by the date of creation. If you want the modification date change this line:
Call add_date(MySubFolder.*DateCreated*, MySubFolder.Name)

For this:
Call add_date(MySubFolder.*DateLastModified*, MySubFolder.Name)

Replace all your code for this:


```
Option Explicit

Dim filedates As New Collection
Dim filenames As New Collection

Private Sub UserForm_Activate()
  Dim fso As Object
  Dim MySubFolder As Object
  Dim MyPath  As String
  Dim i As Long
 
  MyPath = "\\GLC-SERVER\Pulte\Z_Pulte Master Archive\"

  Set fso = CreateObject("Scripting.FileSystemObject")
    
  For Each MySubFolder In fso.GetFolder(MyPath).SubFolders
    Call add_date(MySubFolder.DateCreated, MySubFolder.Name)
  Next MySubFolder
 
  For i = 1 To filenames.Count
    Archive_Open_Year.AddItem filenames(i)
  Next
End Sub

Sub add_date(date1 As Date, name1 As String)
  Dim i As Long
  For i = 1 To filedates.Count
    If filedates(i) <= date1 Then
      filedates.Add date1, before:=i
      filenames.Add name1, before:=i
      Exit Sub
    End If
  Next
  filedates.Add date1
  filenames.Add name1
End Sub
```


----------



## jmpatrick (Dec 20, 2022)

Thanks!


----------

