ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Spreadsheet sorts when saved (https://www.excelbanter.com/excel-worksheet-functions/39967-spreadsheet-sorts-when-saved.html)

Dena

Spreadsheet sorts when saved
 
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?


Alan

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

"Dena" wrote in message
...
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?




Dena

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

"Alan" wrote:

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

"Dena" wrote in message
...
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?






All times are GMT +1. The time now is 05:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com