Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sorting an array
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sorting an array
Seeing as you're skiving off, here's a selection of sorting algorithms to
make you work tomorrow: http://www.cs.ubc.ca/spider/harrison...ting-demo.html "Peter Rooney" wrote: 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sorting an array
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sorting an array
Martin,
I was NOT skiving off! I prefer to think of it as ensuring that I don't succumb to executive burnout via overwork, thus inconveniencing my employer... :-) I'll take a look - thanks! Pete "Martin" wrote: Seeing as you're skiving off, here's a selection of sorting algorithms to make you work tomorrow: http://www.cs.ubc.ca/spider/harrison...ting-demo.html "Peter Rooney" wrote: 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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sorting within an array | Excel Discussion (Misc queries) | |||
Sorting contents of an array | Excel Programming | |||
sorting an array | Excel Programming | |||
Array Sorting in VB | Excel Programming | |||
Sorting 2D Array | Excel Programming |