+ Reply to Thread
Results 1 to 5 of 5

Auto sort drop-down list

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    807

    Auto sort drop-down list

    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.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Auto sort drop-down list

    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.
    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
    Sample attached.
    Attached Files Attached Files
    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 the icon 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!)

  3. #3
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    807

    Re: Auto sort drop-down list

    A rocket scientist, indeed.

    Thanks

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Auto sort drop-down list

    had to sleep after reading post last night but my idea was this
    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
    wher h1:50 contains the validation list and g is an empty column
    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

  5. #5
    Forum Contributor
    Join Date
    12-02-2008
    Location
    Brisbane
    MS-Off Ver
    2016
    Posts
    807

    Re: Auto sort drop-down list

    Thanks for that - an interesting solution.

    Much appreciated

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1