Spreadsheet sorts when saved

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I know there is a way to have a spreadsheet sort the information you add in
to it when you save the spreadsheet. However, I cannot find the path that
leads me to this option.

How do I do that?
 
You need VB code. Copy and paste this into the VB editor, hit Alt and F11 to
open the VB editor, double click the 'This Workbook' icon on the top left,
copy and paste, hit Alt and F11 again to close the VB editor. Change the
sheet and cell references to suit and xlDescending to xlAscending if
required, watch out for text wrap in the e-mail, there should be three lines
of code.
Regards,
Alan.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Sheet1.Range("A1:A30").Sort Key1:=Sheet1.Range("A1"), Order1:=xlDescending
End Sub
 
Hi Alan,

I did as described below and then went into spreadsheet, added info, clicked
save and the info I added didn't sort into the rest of the spreadsheet.

What did I do wrong? Do I need additional info added to VB code?

Thanks
 

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