Stephen Byrom
asked on
Dynamic ActiveX ComboBox on Worksheet
HI,
I have an ActiveX ComboBox on a worksheet that fills with a dynamic array, but I cannot find any code to sort the data.
The list is all dates and I wanted to sort in descending order (newest date first).
The code I have which works is as follows
I have an ActiveX ComboBox on a worksheet that fills with a dynamic array, but I cannot find any code to sort the data.
The list is all dates and I wanted to sort in descending order (newest date first).
The code I have which works is as follows
Private Sub ComboBox1_Change()
Dim daze As String
Dim WB1 As Workbook
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Set WB1 = ActiveWorkbook
Set WS1 = WB1.Sheets("DSVmatrix")
Set WS2 = WB1.Sheets("Movements")
LRdata = WS1.Cells(Rows.Count, 1).End(xlUp).Row
'get the DSV dates for combobox1
For x = 3 To LRdata
If WS1.Cells(x, 9) <> "" And (InStr(daze, "|" & WS1.Cells(x, 9) & "|") = 0) Then
If firsttime = True Then
firsttime = False
daze = "|" & daze & WS1.Cells(x, 9) & "|"
Else
daze = daze & WS1.Cells(x, 9) & "|"
End If
End If
Next x
'build the array and add unique dates to combobox1
myArray = Split(daze, "|")
For Each cell In myArray
If cell <> "" Then
Me.ComboBox1.AddItem cell
End If
Next cell
'how to Sort the combobox data here?
ComboBox1.Value = Format(ComboBox1.Value, "dd-mmm-yyyy")
Sheets("LookUpLists").Range("DSVdate").Value = Me.ComboBox1.Value
Range("DSVfigures").Font.Color = vbBlack
End Sub
but I cannot fathom how to sort it. Any help as always is much appreciated
ASKER
looks tidy, but I cannot fathom how to include or get unique dates from the worksheet (which has over 3000 dates in a column) into the array
Does your current code already add the unique dates to the combobox (but not sorted)? If so can you post that code, or better yet attach the workbook?
ASKER
Hi Martin,
The code is in my first post of this topic
The code is in my first post of this topic
ASKER
here's the book
Testing.xlsm
Testing.xlsm
Sorry that I missed the fact that you had posted the code. How do I get the combobox to appear?
ASKER
Hmmm.
I forgot.
Maybe the sheet is hidden?
Sheets("Movements")
I forgot.
Maybe the sheet is hidden?
Sheets("Movements")
ASKER
on the PasteSheet click the "View Archive" button
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for this Martin, but I cannot get the combobox to populate.
Remove the ListRange reference to the box in the properties window, and the box is empty.
I need the list range to be dynamic so I removed the reference
Remove the ListRange reference to the box in the properties window, and the box is empty.
I need the list range to be dynamic so I removed the reference
ASKER
Thanks for your time and expertise
So is the problem you mentioned in post ID: 41112184 no longer a problem?
ASKER
Yes thanks....... all sorted
You're welcome and I'm glad I was able to help.
In my profile you'll find links to some articles I've written that may interest you
including these two new ones.
Creating your own Excel Formulas and doing the impossible
A Guide to Writing Understandable and Maintainable VBA Code
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
In my profile you'll find links to some articles I've written that may interest you
including these two new ones.
Creating your own Excel Formulas and doing the impossible
A Guide to Writing Understandable and Maintainable VBA Code
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
Open in new window