Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting within an array Steve Excel Discussion (Misc queries) 1 May 31st 07 12:49 PM
Sorting contents of an array Craig Wilks[_2_] Excel Programming 3 April 22nd 05 11:54 PM
sorting an array Ernst Guckel[_4_] Excel Programming 5 March 18th 05 01:45 AM
Array Sorting in VB Randall[_4_] Excel Programming 1 August 24th 04 10:35 PM
Sorting 2D Array ExcelMonkey[_28_] Excel Programming 14 January 28th 04 07:32 PM


All times are GMT +1. The time now is 04:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"