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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a Coloumn

Status
Not open for further replies.

newbie1983

Programmer
Sep 9, 2003
52
GB
I have recorded a macro which sorts a particular coloumn, but i want a universal macro such that when i openup a workbook/worksheet itll sort coloumn D.

Kind Regards

Hinesh
 
You can use your same sorting macro you already developed. Just save it in a workbook in your c:\Program Files\Microsoft Office\Office\Xlstart directory. You will also want to develop a File Open macro that you can run the sorting macro on as soon as it opens.
Code:
Sub fOpen()
Dim fName As String
fName = Application _
    .GetOpenFilename("Excel Files (*.xls), *.xls")
If fName = "" Then
    Exit Sub
End If
Workbooks.Open (fName)
Application.Run "fSort"
End Sub

Private Sub fSort()
ActiveSheet.Range("D1").Sort key1:=Range("D1"), order1:=xlDescending
End Sub
[\code]


Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top