hi,
I am having trouble with a small piece of my project...
i have a userform which enables a user to enter a name and it goes into the listbox...
i need this listbox to sort the names alphabetically...
i have tries all sorts and just can't seem to get it..
hope someone can help... been trying for ages and i'm not getting anywhere
Hi 10121730,
What have you tried?
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
VBA for smarties - snb
As Pike said it is always good to see what you have done rather than writing the whole project for you. The aim of the forum is to help you with your code so you should always have a try first. No one is going to laugh..plenty of people have laughed at my code so don't sweat it. Anyway I can give you an example using a Bubble Sort (I cannot take credit for the method however it is a sort method I use a lot) - try the attached workbook - I have added some names to a listbox and then do a bubble sort on the items and then replace the values into the listbox. You will have to adapt the code for your own needs..
The bubble sort method is as follows however you can see all the code inside the workbook
Where sortItemsArr is the array of names from the listbox.Dim i As Long, k As Long Dim varT As Variant For i = LBound(sortItemsArr, 1) To UBound(sortItemsArr, 1) - 1 For k = i + 1 To UBound(sortItemsArr, 1) If sortItemsArr(i, 0) > sortItemsArr(k, 0) Then varT = sortItemsArr(i, 0) sortItemsArr(i, 0) = sortItemsArr(k, 0) sortItemsArr(k, 0) = varT End If Next k Next i
Hope this helps.
Anthony
“Confidence never comes from having all the answers; it comes from being open to all the questions.”
PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks