+ Reply to Thread
Results 1 to 7 of 7

Automatic sorting

  1. #1
    Forum Contributor
    Join Date
    05-03-2004
    Location
    England
    MS-Off Ver
    2003 Excel
    Posts
    118

    Automatic sorting

    Hi all.
    Is there a way I can get my total data to automatically sort in descending order so as I fill in data into say B3(5 in the table below) the sheet updates accordingly.

    ---A---B---Total
    ---2---1----3
    ---2---5----7

    should automatically sort to

    ---A---B---Total
    ---2---5----7
    ---2---1----3

    it doesn't matter what order they are in if there are 2 totals that are the same as long as they are sorted in descending order.

    Thanks for any help.
    Greg.

    "The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."

  2. #2
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Hi Greg

    You can amend this code to work for your needs

    Private Sub Worksheet_Change(ByVal Target As Range)

    rowcount = Cells(Cells.Rows.Count, "a").End(xlUp).Row
    'you can change the column here change from d to whatever
    Range("a1:" & "d" & rowcount).Select
    'you can change the sort column here change from d to whatever
    'you can change also if there is heater here form Header:=xlNo to Header:=xlYes
    Selection.Sort Key1:=Range("C1"), Order1:=xlDescending, Header:=xlNo, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    'Range("a1").Select

    End Sub

  3. #3
    Forum Contributor
    Join Date
    05-03-2004
    Location
    England
    MS-Off Ver
    2003 Excel
    Posts
    118
    Thank you for that, it works perfecly up to a point.

    My data is slightly more complicated than the original post.

    Some of my data comes from pasted links to other cells in seperate sheets in the workbook.

    If I change anything on the summary sheet other than the linked cells the auto sort works great.

    When I change cells in the other sheets the linked ones on the summary sheet change but the auto sort does not calculate.

    I hope this is clear.

    Can anyone help me a little bit further.

    Cheers.

  4. #4
    Forum Contributor
    Join Date
    05-03-2004
    Location
    England
    MS-Off Ver
    2003 Excel
    Posts
    118
    is there no way to fix this?

  5. #5
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Hi Greg

    I was away for a bit, I was reading your comment and it is not clear to me what you want. Can you post a sample of what you have and what you would like the macro to do.

    Thanks
    Denis

  6. #6
    Forum Contributor
    Join Date
    05-03-2004
    Location
    England
    MS-Off Ver
    2003 Excel
    Posts
    118
    Denis, thanks for replying.

    In my original post

    the data for column A is put in directly on that sheet (sheet 1)

    the data for column B comes from links to cells in sheet 2.

    When I alter the cells in sheet 1 the macro works fine and autosorts.

    When I alter the cells in sheet 2 the linked cells in sheet 1 change but the auto sort does not kick in.

    edit: I have just realised that when I change the cells in sheet 2, sheet 1 will not auto sort until I have edited any other cell. How do I get it to autosort straight away likeit does when you change the data in sheet 1.
    I have attached a file showing what is happening.

    Hope this makes it a bit clearer.
    Attached Files Attached Files
    Last edited by greg7468; 09-20-2006 at 10:46 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Hi Greg

    See attached spreadsheet, I hope it meet your requirements

    Thanks
    Denis
    Attached Files Attached Files

+ 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