Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort an array

Status
Not open for further replies.

bozic12

MIS
Jan 23, 2003
48
US
Is there anyway in VBA to sort a populated array. I'm pulling data from a worksheet based on selected model numbers in a combobox that are controlled from a different worksheet. When I display the array in a list box, it's not in the same order as the first worksheet because it doesn't get "pulled" off the worksheet in the order it's listed. It will work if I sort both worksheets by the same two columns, but for recording reasons, I don't want to do that. I also know I could temporarily paste the array to a column on a worksheet, then sort it, then repopulate the array, but it would be easier if I could just sort it in the code. Thanks for any help!!
 
I'm sure you'll hear a better way from someone, but if not have you tried simple triangular or bubble sorts, etc?
 
if you search the internet for "vba sort array" you'll come up with a million good answers to this one.... several different methods (including those suggested by mscallisto).
 
mscallisto, i can't do a simple sort because i am sorting strings, bubble sorts and quick sorts only sort integers. euskadi, i did find some good sorting methods online, but it ended up that for what i was sorting, it was just easiest to paste it to a worksheet and use excel's sorting capabilities. thank you both though for your suggestions.
 
I forget what quicksort is, but bubble sort (or even simpler, selection sort) works with any kind of data type for which you can use the < operator, or for which you can write a
function SmallerThan(item1,item2) as boolean

Still, sorting through Excel is easy enough, and does the trick.
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top