View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter Rooney Peter Rooney is offline
external usenet poster
 
Posts: 325
Default Sorting an array

Tom,

Thanks very much for this - it works fine! :-)

Regards

Pete




"Tom Ogilvy" wrote:

This uses the slow but simple bubble sort, but it shouldn't be an issue with
a small number of files.

Sub SortFiles()
Dim i As Long, temp As String
Dim v As Variant, j As Long
v = Application.GetOpenFilename(MultiSelect:=True)
If UBound(v) - LBound(v) 0 Then
For i = LBound(v) To UBound(v) - 1
For j = i + 1 To UBound(v)
If LCase(v(i)) LCase(v(j)) Then
temp = v(i)
v(i) = v(j)
v(j) = temp
End If
Next
Next
End If
j = 1
For i = LBound(v) To UBound(v)
Cells(j, 3).Value = v(i)
j = j + 1
Next
End Sub

--
Regards,
Tom Ogilvy


"Peter Rooney" wrote in message
...
Good afternoon.

I have a routine that allows the user to select one or several files from
the fileopen dialog box. If the user selects multiple files, is there any

way
in which they can be stored to the elements of the array in alphabetical
order e.g. element 1 contains test1.xls, element 2 contains test4.xls,
element 3 contains testX.xls etc?

At the moment, a multiple select seems uncontrollable as to which filename
gets stored in each element.

Thanks in advance and see you in the morning!

Pete