Results 1 to 6 of 6

Add Sort Button

This is a discussion on Add Sort Button within the Excel Questions forums, part of the Question Forums category; Is there an easy way to add a "sort" button in a column heading name to sort on that particular ...

  1. #1
    Board Regular
    Join Date
    Mar 2004
    Posts
    52

    Default Add Sort Button

    Is there an easy way to add a "sort" button in a column heading name to sort on that particular field and include all the data in a row. I would like to have multiple sort buttons. See screen shot below. I would like to sort the Project , Milestone Start Date or Stop Date Columns.

    Thanks
    Kevin

    ******** ******************** ************************************************************************>
    Microsoft Excel - Project Summary Master.xls___Running: xl2002 XP : OS = Windows XP
    (F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)bout
    =

    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    1
    **************
    2
    ConCor*Domain*Milestones*************
    3
    **************
    4
    ProjectMilestoneStart*DateStop*Date12/1/0312/15/200312/29/031/12/20041/26/042/9/20042/23/043/8/20043/22/044/5/2004
    5
    **************
    6
    **************
    7
    **************
    8
    **************
    9
    **************
    10
    **************
    Gantt Chart*

    [HtmlMaker 2.42] To see the formula in the cells just click on the cells hyperlink or click the Name box
    PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.

  2. #2
    Board Regular Drdave1958's Avatar
    Join Date
    Mar 2002
    Location
    Sitting here inside myself
    Posts
    204

    Default Re: Add Sort Button

    Here's something I got from the board that may be of use...modify to suit.

    Code:
    Private Sub CommandButton1_Click()
      Static iOrder As Integer
      Dim oRange As Range
        If iOrder = xlAscending Then
            iOrder = xlDescending
        Else
            iOrder = xlAscending
        End If
      'Use object variable to hold the target range
      Set oRange = Range("A2:E2")
      'Adjust target range to incorporate continuous data cells below A2 and E2
      Set oRange = Range(oRange, oRange.End(xlDown))
      oRange.Sort Key1:=Range("A2"), Order1:=iOrder, Header:=xlGuess, _
      OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    End Sub
    -Dave-

  3. #3
    Board Regular
    Join Date
    Mar 2004
    Posts
    52

    Default Re: Add Sort Button

    Dave

    I'm fairly new to VBA, can you give a brief intro as to what this does?

    Thanks
    Kevin

  4. #4
    Board Regular Drdave1958's Avatar
    Join Date
    Mar 2002
    Location
    Sitting here inside myself
    Posts
    204

    Default Re: Add Sort Button

    The sheet I have this on contains data in 5 columns, A thru E. I have a button on my worksheet this macro is assigned to. Click the button and it sorts column A either ascending or descending (the other columns follow along). Click it again and it sorts the opposite.

    This part determines which column you're sorting by.....
    Code:
    Key1:=Range("A2")
    -Dave-

  5. #5
    Board Regular
    Join Date
    Mar 2004
    Posts
    52

    Default Re: Add Sort Button

    Dave

    I sort of have this working. I need to specify a limited number of rows. Example: rows 5-50 only if they are non-blank. How would I code for this?

    Thanks
    Kevin

  6. #6
    New Member
    Join Date
    Oct 2007
    Posts
    3

    Default

    This works awesome! I have one related problem thouhg. When sorting numbers it sorts them like this: 1,10,11,2,21,27,3,35. But I would like it to sort like this: 1,2,3,10,11,21,27,35. Does anyone know how to make it sort like this without putting a 0 in front of the single digit numbers?
    thx! I guess I didn't have my cells formatted as numbers. now it works!

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com