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 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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.