Sort an array to use in a listbox on a userform in Excel 2007
Sub sortarray()
Dim sfiles(8, 2) '<= this line is optional depending how your array is
defined
SortRow = 0 'could be 0 or 1
For i = 0 To (UBound(sfiles) - 1)
For j = 1 To UBound(sfiles)
If sfiles(i, SortRow) sfiles(j, SortRow) Then
'swap data items
temp = sfiles(i, 0)
sfiles(i, 0) = sfiles(j, 0)
sfiles(j, 0) = temp
temp = sfiles(i, 1)
sfiles(i, 1) = sfiles(j, 1)
sfiles(j, 1) = temp
End If
Next j
Next i
End Sub
"Renate" wrote:
Hi guys,
Please bear with me, I can't get this sorting the way I need it to
work. I've serached on the archives, but somehow I couldn't find an
example that works for my array.
The array contains filenames including the path etc and some sort of
description which I create from leaving parts out of the filename,
for example:
sFiles(0,0) = "c:\AB 123.xls"
sFiles(1,0) = "123"
sFiles(0,1) = "c:\AB 234.xls"
sFiles(1,1) = "234"
sFiles(0,2) = "c:\AB 898.xlam"
sFiles(1,2) = "898"
sFiles(0,2) = "c:\999.doc"
sFiles(1,2) = "999"
I use this data in a listbox with two columns. Only one of the columns
is visible to the user. I want to create an option on the userform to
sort the listbox on either the fullname or on the description.
How can I archieve this?
|