Add Sort Button

kmurtha

Board Regular
Joined
Mar 24, 2004
Messages
52
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
Project Summary Master.xls
ABCDEFGHIJKLMN
1
2ConCorDomainMilestones
3
4ProjectMilestoneStartDateStopDate12/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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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-
 
Upvote 0
Dave

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

Thanks
Kevin
 
Upvote 0
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-
 
Upvote 0
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
(y)
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,315
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top