auto sort automatically on save

W

WylieDude

Is there a way I can have my sheet autosort selected rows when I re-save the
sheet after adding new data.

Thanks in Advance
 
M

mudraker

You can use a before save event macro



eg

this code goes on the Workbook module sheet and sort columns a & b of
the active sheet

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Columns("A:B").Sort Key1:=Range("A1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
 
W

WylieDude

With that sample I get "Compile Error Expected: type name

You'll have to excuse me as I am relatively new to trying to mess with
excel. Any help appreciated. Thanks in Advance

Here is the code I am trying:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Columns("C").Sort Key1:=Range("C12:C20"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
 
M

mudraker

WylieDude

The following is a Single line command. -I did not notice that it had
been word wrapped when I originally posted


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

Move Boolean) back to the previous line after Cancel As
 
Top