sort

G

Gord Dibben

Dave

By "sort a file" do you mean you want to sort a worksheet when you open the
file(workbook)?

Private Sub Workbook_Open()
Sheets("MySheet").Activate
Columns("C:H").Select
Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Substitute MySheet for your sheetname and the range and sortkey will be
adapted to your needs.

Right-click on the Excel Icon at top left of Menu Bar and "View Code".

The above code would be pasted in there.

The code runs when the workbook is opened.

If not what you want, post back.

Gord Dibben Excel MVP
 
D

Don Guillett

try recording a macro of your sort and put in your workbook_open event to be
found in the ThisWorkbook module.
 
Top