Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Sort Combobox List

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
T De Villiers - 21 Jan 2006 13:57 GMT
Hi,

I would like to sort a combox List by ascending order.
Currently, my macro does the following fine, need
additional code to sort the data, many thks

Private Sub ComboBox1_DropButtonClick()
Dim sh As Worksheet

ComboBox1.Clear
For Each sh In ActiveWorkbook.Worksheets
ComboBox1.AddItem sh.Name

Next
End Sub

Signature

T De Villiers

Toppers - 21 Jan 2006 14:53 GMT
Hi,

        HTH

Sub SortSheets()

'   This routine sorts the sheets of the
'   active workbook in ascending order.
     
   Dim SheetNames() As String  
     
'   Get the number of sheets
   SheetCount = ActiveWorkbook.Sheets.Count
   
'   Redimension the arrays
   ReDim SheetNames(1 To SheetCount)
   

'   Fill array with sheet names
   For i = 1 To SheetCount
       SheetNames(i) = ActiveWorkbook.Sheets(i).Name
   Next i
 
'      
'   Sort the array in ascending order
   Call BubbleSort(SheetNames)
 
 For i = 1 To SheetCount
       Combobox1.additem SheetNames(i)
   Next i

   
End Sub

Sub BubbleSort(List() As String)
'   Sorts the List array in ascending order
   Dim First As Integer, Last As Integer
   Dim i As Integer, j As Integer
   Dim Temp
 
   First = LBound(List)
   Last = UBound(List)
   For i = First To Last - 1
       For j = i + 1 To Last
           If List(i) > List(j) Then
               Temp = List(j)
               List(j) = List(i)
               List(i) = Temp
           End If
       Next j
   Next i
End Sub

> Hi,
>
[quoted text clipped - 11 lines]
> Next
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.