ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Sort excel when workbook opened (https://www.excelbanter.com/excel-discussion-misc-queries/244640-sort-excel-when-workbook-opened.html)

LTOSH

Sort excel when workbook opened
 
I have a workbook with currently 11 worksheets. I am wanting to
automatically sort Column A of each worksheet. I have placed the following
code within my workbook:

Private Sub Workbook_Open()
Worksheets("Abs").Select
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, header:=xlyes
End Sub

:and it works fine but ONLY with the first worksheet becuase it is named ABS.
What do i need to put in the code to also sort the other worksheets??
(Sample names of other worksheets...Back, Biceps, Cardio)

thanks!
LTOSH

Jacob Skaria

Sort excel when workbook opened
 
Try the below instead..

Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In Me.Worksheets
ws.Cells.Sort Key1:=ws.Range("A1"), _
Order1:=xlAscending, Header:=xlYes
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"LTOSH" wrote:

I have a workbook with currently 11 worksheets. I am wanting to
automatically sort Column A of each worksheet. I have placed the following
code within my workbook:

Private Sub Workbook_Open()
Worksheets("Abs").Select
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, header:=xlyes
End Sub

:and it works fine but ONLY with the first worksheet becuase it is named ABS.
What do i need to put in the code to also sort the other worksheets??
(Sample names of other worksheets...Back, Biceps, Cardio)

thanks!
LTOSH


LTOSH

Sort excel when workbook opened
 
worked perfectly thank you so much!!!!!!

"Jacob Skaria" wrote:

Try the below instead..

Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In Me.Worksheets
ws.Cells.Sort Key1:=ws.Range("A1"), _
Order1:=xlAscending, Header:=xlYes
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"LTOSH" wrote:

I have a workbook with currently 11 worksheets. I am wanting to
automatically sort Column A of each worksheet. I have placed the following
code within my workbook:

Private Sub Workbook_Open()
Worksheets("Abs").Select
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, header:=xlyes
End Sub

:and it works fine but ONLY with the first worksheet becuase it is named ABS.
What do i need to put in the code to also sort the other worksheets??
(Sample names of other worksheets...Back, Biceps, Cardio)

thanks!
LTOSH



All times are GMT +1. The time now is 02:50 AM.

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