+ Reply to Thread
Results 1 to 4 of 4

Need help on automatic sorting

Hybrid View

  1. #1
    Registered User
    Join Date
    07-01-2010
    Location
    Luxembourg, Luxembourg
    MS-Off Ver
    Excel 2019
    Posts
    85

    Need help on automatic sorting

    I've got a file with several worksheets and I need to have an automatic sort (descending) for different parts in several columns and this should be working for all the worksheets.

    In attached file the areas to be sorted are in yellow.

    Could please somebody help me out with this problem.

    Many thanks in advance
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need help on automatic sorting

    This seems to work with everything except the R column. Cells are merged.

    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    
    Range("H11:H48").Sort Key1:=Range("H11"), Order1:=xlDescending
    Range("H60:H97").Sort Key1:=Range("H60"), Order1:=xlDescending
    Range("H109:H146").Sort Key1:=Range("H109"), Order1:=xlDescending
    Range("H158:H196").Sort Key1:=Range("H158"), Order1:=xlDescending
    Range("Q11:Q48").Sort Key1:=Range("Q11"), Order1:=xlDescending
    Range("Q60:Q97").Sort Key1:=Range("Q60"), Order1:=xlDescending
    Range("Q109:Q146").Sort Key1:=Range("Q109"), Order1:=xlDescending
    'Range("R160:R196").Sort Key1:=Range("R160"), Order1:=xlDescending
    Range("Z11:Z48").Sort Key1:=Range("Z11"), Order1:=xlDescending
    Range("Z60:Z97").Sort Key1:=Range("Z60"), Order1:=xlDescending
    Range("AA111:AA146").Sort Key1:=Range("AA111"), Order1:=xlDescending
    
    End Sub

  3. #3
    Registered User
    Join Date
    07-01-2010
    Location
    Luxembourg, Luxembourg
    MS-Off Ver
    Excel 2019
    Posts
    85

    Re: Need help on automatic sorting

    Hi,

    Many thanks for your answer.

    As I've got no knowledge of VBA could you please tell me how to proceed in order to get this into my file.

    What should be changed if there are no merged cells anymore?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Need help on automatic sorting

    I don't have 2010 excel. However, I do know you need to go to the developer's tab. Open the Visual Basic Editor. In the editor on the lefthand side there should be a VBA project window. Click on ThisWorkbook. A pop-up on the righthand side will appear. Under General choose Workbook. Under Declarations choose Sheet Activate. The code goes there.

    In your sheets Range("R160:R196") are merged you need to unmerge them if you want that range sorted. As the code stands now it will skip that range. If you unmerged them then you have to edit the code. See the line for that range within the code. There is a little tick mark in front of that range. Just remove it.

+ 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