Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Dates in Excel. 1

Status
Not open for further replies.

CEG

Technical User
Feb 13, 2002
22
0
0
GB
User keeps spreadsheet for leases. Would like to sort by using the first date in the Lease Commence column.

Please Help

Thanking you in anticipation.

CEG
 
Hi,
With any cell selected within the table that you want to sort...

1. Menu Item - Data/Sort

2. If your table has a header row, select the header row option button

3. Select the column(s) you wish to inclde as sort items

4. Select ascending or descending option button(s)

5. Hit OK and VOLA

Note: For sorting on a single column, select a cell in the column and activate the Sort Ascending or sort Descending Toolbar Icon

Hope this helps :) Skip,
metzgsk@voughtaircraft.com
 
Once again, a "team effort"... :)

Here's some VBA code, in case you would like to set up a macro button that would enable you to easily sort - with just a "click of the button".

Dim First_Cell, Last_Cell, sort_type As String

Sub Sort_Data()
Set_DataRange
Sort_ByDate
End Sub

Sub Set_DataRange()
Application.ScreenUpdating = False
Application.Goto Reference:="data"
First_Cell = ActiveCell.Address
Set_LastCell
Data_Range = First_Cell & ":" & Last_Cell
Range(Data_Range).Name = "data"
Application.Goto Reference:="R1C1"
Application.ScreenUpdating = True
End Sub

Sub Set_LastCell() 'determines the LAST cell used in the sheet
'Note: IF the sheet contains more data than the table
'being sorted, then you will NEED to eliminate the
'LastColumn row below, and then on the last row,
'change it to read: Last_Cell = "X" & usedrows,
'where you replace "X" with the last column of your table.
usedrows = [A65536].End(xlUp).Row
LastColumn = Chr(64 + ActiveSheet.UsedRange.Columns.Count)
Last_Cell = LastColumn & usedrows
End Sub

Sub Sort_ByDate()
Application.ScreenUpdating = False
Application.Goto Reference:="data"
Selection.Sort Key1:="Field1", Order1:=xlAscending, _
Key2:="Field2", Order2:=xlAscending, _
Key3:="Field3", Order2:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
ActiveCell.Offset(-2, 0).Select
sort_type = "Field1, Field2, Field3"
Set_Type
Application.ScreenUpdating = True
End Sub

Sub Set_Type()
'This places a label at the top of the data, to show the "type
'of sort" that has been done. This is really ONLY required when
'there are additional sort options (additonal sort buttons) where
'the user can sort by "various sort orders".
Range("type").Value = "Sorted by: " & sort_type
End Sub


If you would like, I could email you a copy of this file. Just email me, and I'll send the file via return email.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top