+ Reply to Thread
Results 1 to 2 of 2

Thread: Sorting data on workbook opening

  1. #1
    Registered User
    Join Date
    03-13-2010
    Location
    Bedfordshire, England
    MS-Off Ver
    Excel 2003
    Posts
    49

    Sorting data on workbook opening

    I have the following code which on workbook opening sets a password, sorts the data in a worksheet and hides some lines. I want to apply this to two other worksheets in the same workbook call YEAR ONE & FOUNDATION but cant seem to get it to work. Anybody got any advice or pointers. After the sorting I still need it to select cells A1:A5 in YEAR TWO worksheet.


    Private Sub Workbook_Open()
    Dim ws As Worksheet
    
    For Each ws In Worksheets
        ws.Protect "mark", UserInterfaceOnly:=True
        Sheets("YEAR TWO").Select
        ActiveWindow.DisplayGridlines = False
        Rows("145:900").Select
        Selection.EntireRow.Hidden = True
        ActiveWindow.ScrollColumn = 3
        ActiveWindow.ScrollRow = 6
        Range("A1:A5").Select
        Range("A6:GD123").Select
        Selection.Sort Key1:=Range("C6"), Order1:=xlDescending, Key2:=Range("D6") _
            , Order2:=xlAscending, Key3:=Range("A6"), Order3:=xlAscending, Header:= _
            xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
            xlSortNormal
            ActiveWindow.ScrollRow = 6
            Range("A1:A5").Select
        
        Next ws
    
    
    End Sub

  2. #2
    Registered User
    Join Date
    03-13-2010
    Location
    Bedfordshire, England
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Sorting data on workbook opening

    I have tried the following hoping it would sort YEAR ONE then move to YEAR TWO worksheet and sort that but I get an error, I'm just starting out in VBA and don't really understand what is wrong.

    Any help gratefully recieved.


    Private Sub Workbook_Open()
    Dim ws As Worksheet
    
    For Each ws In Worksheets
        ws.Protect "mark", UserInterfaceOnly:=True
    Sheets("YEAR ONE").Select
        ActiveWindow.DisplayGridlines = False
        Rows("145:900").Select
        Selection.EntireRow.Hidden = True
        ActiveWindow.ScrollColumn = 3
        ActiveWindow.ScrollRow = 6
        Range("A1:A5").Select
        Range("A6:GD123").Select
        Selection.Sort Key1:=Range("C6"), Order1:=xlDescending, Key2:=Range("D6") _
            , Order2:=xlAscending, Key3:=Range("A6"), Order3:=xlAscending, Header:= _
            xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
            xlSortNormal
            ActiveWindow.ScrollRow = 6
            Range("A1:A5").Select
        Sheets("YEAR TWO").Select
        ActiveWindow.DisplayGridlines = False
        Rows("145:900").Select
        Selection.EntireRow.Hidden = True
        ActiveWindow.ScrollColumn = 3
        ActiveWindow.ScrollRow = 6
        Range("A1:A5").Select
        Range("A6:GD123").Select
        Selection.Sort Key1:=Range("C6"), Order1:=xlDescending, Key2:=Range("D6") _
            , Order2:=xlAscending, Key3:=Range("A6"), Order3:=xlAscending, Header:= _
            xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
            xlSortNormal
            ActiveWindow.ScrollRow = 6
            Range("A1:A5").Select
        
        Next ws
    
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0