View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Combo Box question

You could sort the data yourself before you add it to the combobox.

John Walkenbach shows a way to use a collection in this code:
http://www.j-walk.com/ss/excel/tips/tip47.htm

He's actually filling a listbox with that unique list that's sorted, but you
could modify the code to sort in reverse order.

Or you could loop through your range in reverse order.

If that DateList is a single column, you could use:

Option Explicit
Private Sub UserForm_Initialize()
Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long

With ActiveSheet.Range("DateList")
FirstRow = .Row
LastRow = .Cells(.Cells.Count).Row

For iRow = LastRow To FirstRow Step -1
If .Cells(iRow).Value < .Cells(iRow - 1).Value Then
Me.cBoxDates.AddItem Format(.Cells(iRow).Value, "m/d/yyyy")
End If
Next iRow
End With
End Sub

===
Although, I'd use a unambiguous date format like: mmm dd, yyyy

If that range is multiarea or multicolumn, then the code would have to change.



Sam wrote:

I have a list of dates that has several of the same date, however they are in
chronological order, named DateList. A combo box in a userform displays these
with the UserForm_Initialize event:

For each c in Range("DateList")
If c < c.Offset(-1, 0) Then
Me.cBoxDates.AddItem Format(c, "m/d/yyyy")
End If
Next

How can I get the combo box to display the dates in reverse order (latest to
earliest) if the list is earliest to latest?

Thanks,

Sam


--

Dave Peterson