ylecoyote
asked on
visual basic for applications listbox sort
I'm trying to sort the contents of my listbox, but my version of VBA doesn't offer it as a property of the listbox (in the properties box). What would the code be to do this?
Thanks
Thanks
If listbox is populated with ramdom values, populate a hidden range first, sort that range and use it as RowSource property.
ASKER
Thanks for your response. I am still a little unclear. I'm new to VB. This is where and how I am populating the listbox.
The available worksheets change at any time, so they need to select from a list of available worksheets. This macro is for an excel spreadsheet by the way.
++++++++++++++++++++++++++ ++++++++++ ++++++++++ +++++++
Private Sub UserForm_Activate()
For i = 1 To Worksheets.Count
If UCase(Left(Worksheets(i).N ame, 9)) <> "TEMPLATE_" Then
If UCase(Worksheets(i).Name) = "LOG" Or UCase(Worksheets(i).Name) = "HELP" Or Worksheets(i).Name = ActiveCell.Worksheet.Name Then
Else
lstHolder.AddItem (Worksheets(i).Name)
End If
End If
Next i
End Sub
The available worksheets change at any time, so they need to select from a list of available worksheets. This macro is for an excel spreadsheet by the way.
++++++++++++++++++++++++++
Private Sub UserForm_Activate()
For i = 1 To Worksheets.Count
If UCase(Left(Worksheets(i).N
If UCase(Worksheets(i).Name) = "LOG" Or UCase(Worksheets(i).Name) = "HELP" Or Worksheets(i).Name = ActiveCell.Worksheet.Name Then
Else
lstHolder.AddItem (Worksheets(i).Name)
End If
End If
Next i
End Sub
Instead of populate
lstHolder.AddItem (Worksheets(i).Name)
populate a hidden range, sort it and use
lstHolder.RowSource to that range
lstHolder.AddItem (Worksheets(i).Name)
populate a hidden range, sort it and use
lstHolder.RowSource to that range
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi ylecoyote,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept Richie_Simonetti's comment(s) as an answer.
ylecoyote, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept Richie_Simonetti's comment(s) as an answer.
ylecoyote, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
per recommendation
SpideyMod
Community Support Moderator @Experts Exchange
SpideyMod
Community Support Moderator @Experts Exchange
if use a range, sort the range.
If you do manually, add items in right order.
Hope it helps
Cheers