Is it possible to autosort a drop-down list based on the number of times an item is selected? A drop-down might have 500 lines so it is user-friendly if the top lines are those selected by users the most often.
Any ideas?
Is it possible to autosort a drop-down list based on the number of times an item is selected? A drop-down might have 500 lines so it is user-friendly if the top lines are those selected by users the most often.
Any ideas?
Last edited by BRISBANEBOB; 06-14-2009 at 08:36 PM.
Here's a sample worksheet_change macro to do this, only way I could think of. Basically, a "count" column next to your validation list makes a simple sort on the names/values do the work.
Sample attached.![]()
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim MyRow As Long If Target.Count > 1 Or Target = "" Then Exit Sub If Not Intersect(Target, Range("G:G")) Is Nothing Then Application.EnableEvents = False MyRow = WorksheetFunction.Match(Target, Range("Names"), 0) Cells(MyRow, "B") = Cells(MyRow, "B") + 1 Range("NameSort").Sort Key1:=Range("B1"), Order1:=xlDescending, Key2:=Range("A1"), Order2:=xlAscending Application.EnableEvents = True End If End Sub
Last edited by JBeaucaire; 06-14-2009 at 08:29 PM. Reason: Updated macro to sort by column A, too
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
A rocket scientist, indeed.
Thanks
had to sleep after reading post last night but my idea was this
wher h1:50 contains the validation list and g is an empty column![]()
Private Sub Worksheet_Change(ByVal Target As Range) Application.ScreenUpdating = False Dim mymatch As Integer Dim myrange As String If Target.Address <> "$A$1" Then Exit Sub mymatch = Application.WorksheetFunction.Match(Range("a1"), Range("h1:h500"), 0) myrange = "g" & mymatch Range(myrange) = Range(myrange) + 1 Columns("G:H").Sort Key1:=Range("G1"), Order1:=xlDescending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal Application.ScreenUpdating = True End Sub
somewhat similar to jb's tho
"Unless otherwise stated all my comments are directed at OP"
Mojito connoisseur and now happily retired
where does code go ?
look here
how to insert code
how to enter array formula
why use -- in sumproduct
recommended reading
wiki Mojito
how to say no convincingly
most important thing you need
Martin Wilson: SPV
and RSMBC
Thanks for that - an interesting solution.
Much appreciated
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks