Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sort Combobox List


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


--
T De Villiers
------------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...o&userid=26479
View this thread: http://www.excelforum.com/showthread...hreadid=503613

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Sort Combobox List

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



"T De Villiers" wrote:


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


--
T De Villiers
------------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...o&userid=26479
View this thread: http://www.excelforum.com/showthread...hreadid=503613


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
.AddItem list and populating combobox with created list pallaver Excel Discussion (Misc queries) 8 June 27th 08 12:36 PM
sort/filter combobox mandy Excel Discussion (Misc queries) 0 December 12th 05 06:08 AM
Sort Data in a combobox list Kryer Excel Programming 0 November 16th 05 10:29 PM
Sort Data in a combobox list Toppers Excel Programming 0 November 16th 05 08:59 PM
ComboBox list reliant on the entry from a different ComboBox ndm berry[_2_] Excel Programming 4 October 4th 05 04:40 PM


All times are GMT +1. The time now is 12:05 PM.

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"