+ Reply to Thread
Results 1 to 4 of 4

Data sorted when sheet opens

Hybrid View

  1. #1
    Registered User
    Join Date
    12-15-2003
    Location
    UK
    Posts
    52

    Data sorted when sheet opens

    Hi Folks

    Just a quick one, hope its an easy one for someone.

    How do i make a sheet sort a small table of data from A-Z automatically every time i open that sheet?

    Any ideas.

    Cheers in Advance

    Chris

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Data sorted when sheet opens

    Paste the following macro into the ThisWorkbook tab in the VBA editor (Alt F11) and adjust as necessary to specify the sheet, the range of data and the column to sort by.

    Private Sub Workbook_Open()
    Sheets("MySheetName").Cells(1, 1).CurrentRegion.Sort Header:=xlYes, key1:=Sheets("MySheetName").Cells(1, 1), order1:=xlAscending
    End Sub
    Last edited by mrice; 01-30-2010 at 09:25 AM.
    Martin

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Data sorted when sheet opens

    Hi,
    I'm assuming when you refer to a sheet in your original post, you really do mean a sheet and not the workbook.

    In the VBE use the Sheet_Activate event procedure and enter the following line of code
    Private Sub Worksheet_Activate()
        Range("A1").CurrentRegion.Sort key1:=Range("A2"), order1:=xlAscending, header:=xlYes
    End Sub
    change the order:= if necessary to xlDescending, and add further sort keys if required.

    If you mean when you open the workbook then use the same line of code in the Workbook_Open event.

    HTH
    Last edited by Richard Buttrey; 01-30-2010 at 09:24 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    12-15-2003
    Location
    UK
    Posts
    52

    Re: Data sorted when sheet opens

    Hi Richard

    Thanks very much, this works a treat, Muchly Appreciated.

    Thanks Again

    Chris

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1