Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Alphabetize a combo box list?

Anyone got code that will put the items in a combobox in alphabetical order?

Thanks!

Dan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Alphabetize a combo box list?

Dan,

In Excel, I've always used a rowsource that was a sorted list somewhere in
my workbook so the items didn't need to be sorted again. However, here is a
modified version of something I've used in a Word subroutine. The routine
below populates combobox1 found in a userform at the time the userform is
activated.

_____________________________

Private Sub UserForm_Activate()

Const adVarChar = 200
Const MaxCharacters = 255

Dim myArray As Variant
Dim myItem As Variant

myArray = Array("Tom", "Dick", "Harry")

Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "myComboList", adVarChar, MaxCharacters
DataList.Open

For N = 0 To UBound(myArray)
DataList.AddNew
DataList("myComboList") = myArray(N)
DataList.Update
Next N

DataList.Sort = "myComboList"

DataList.MoveFirst
Do Until DataList.EOF
ComboBox1.AddItem (DataList.Fields.Item("myComboList"))
DataList.MoveNext
Loop

End Sub

____________________________

Steve Yandl


"Dan" wrote in message
...
Anyone got code that will put the items in a combobox in alphabetical
order?

Thanks!

Dan



  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Alphabetize a combo box list?

Steve -
Thanks so much. I was able to modify your code and get it incorporated in to
mine, and it does the trick. I have never used a recordset before, so I am
learning something new.
Dan

"Steve Yandl" wrote:

Dan,

In Excel, I've always used a rowsource that was a sorted list somewhere in
my workbook so the items didn't need to be sorted again. However, here is a
modified version of something I've used in a Word subroutine. The routine
below populates combobox1 found in a userform at the time the userform is
activated.

_____________________________

Private Sub UserForm_Activate()

Const adVarChar = 200
Const MaxCharacters = 255

Dim myArray As Variant
Dim myItem As Variant

myArray = Array("Tom", "Dick", "Harry")

Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "myComboList", adVarChar, MaxCharacters
DataList.Open

For N = 0 To UBound(myArray)
DataList.AddNew
DataList("myComboList") = myArray(N)
DataList.Update
Next N

DataList.Sort = "myComboList"

DataList.MoveFirst
Do Until DataList.EOF
ComboBox1.AddItem (DataList.Fields.Item("myComboList"))
DataList.MoveNext
Loop

End Sub

____________________________

Steve Yandl


"Dan" wrote in message
...
Anyone got code that will put the items in a combobox in alphabetical
order?

Thanks!

Dan




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
How do i alphabetize a list? Woodsa Excel Discussion (Misc queries) 3 July 30th 08 11:52 PM
How do you alphabetize a list in xcel? ArCar Excel Discussion (Misc queries) 1 August 3rd 06 11:39 PM
How to alphabetize my created list? helpanewbie New Users to Excel 3 April 10th 05 09:49 AM
How to alphabetize my created list? etakathy New Users to Excel 2 April 8th 05 03:11 PM
how to alphabetize a list in Excel DJ Somers Excel Worksheet Functions 4 January 1st 05 03:39 AM


All times are GMT +1. The time now is 10:11 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"