auto sort automatically on save

  • Thread starter Thread starter WylieDude
  • Start date Start date
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
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top