+ Reply to Thread
Results 1 to 6 of 6

Auto Sort

Hybrid View

  1. #1
    Registered User
    Join Date
    05-18-2012
    Location
    Old Bethpage, NY
    MS-Off Ver
    Excel 2010
    Posts
    3

    Auto Sort

    Hi,

    Currently any time I add a number in worksheet one it automatically updates on worksheet 2. I would like to be able automatically sort worksheet 2 based on the new numbers as they are added. Is this possible. While I'm pretty proficient in Excel, I have been trying to figure out how to make this work for hours to no avail. I know I can data sort each time, but it's a lot of information and I'd like it to just do it for me

    Any help is greatly appreciated!!

    Lorin

  2. #2
    Registered User
    Join Date
    08-30-2010
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Auto Sort

    How was this auto-update done?
    May I view the code so that I can make sure it doesn't interfere with it?

    In what order is the data sorted? Provide an example.

    and finally, if you can attach your workbook or dummy workbook so that we have easier time understanding which column you are trying to sort in what ways and such.

  3. #3
    Registered User
    Join Date
    05-18-2012
    Location
    Old Bethpage, NY
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Auto Sort

    Hi,
    I'm attaching a dummy workbook. Feel free to mess around with it...it's updated by the sum function. I got this worksheet from somebody and they asked me to work it so it's mostly automated...any suggestions are greatly appreciated!!

    Lorin

    Quote Originally Posted by kpark91 View Post
    How was this auto-update done?
    May I view the code so that I can make sure it doesn't interfere with it?

    In what order is the data sorted? Provide an example.

    and finally, if you can attach your workbook or dummy workbook so that we have easier time understanding which column you are trying to sort in what ways and such.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Auto Sort

    This should do what you want:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim LastRow As Long
        Dim ws As Worksheet
        
        Set ws = Sheets(2)
        
        LastRow = ws.UsedRange.Rows.Count
        
        With ws.Sort
            .SortFields.Clear
            .SortFields.Add Key:=Range("C8:C" & LastRow) _
            , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
            .SetRange Range("A8:C" & LastRow)
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End Sub
    You have to place the code in the module that corresponds to sheet1, check the attachment to see how.
    dummyworkbook.xlsm
    .?*??)
    `?.???.?*??)?.?*?)
    (?.?? (?.?
    Pichingualas <---
    ??????????????????????????

    Wrap your code with CODE TAGS.
    Thank those who helped you, Don't forget to add to their REPUTATION!!! (click on the star below their post).
    Please mark your threads as [SOLVED] when they are (Thread Tools->Mark thread as Solved).

  5. #5
    Registered User
    Join Date
    05-18-2012
    Location
    Old Bethpage, NY
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Auto Sort

    Wow, thank you so much!! that's exactly what I needed. The only thing is it's a little glitchy because if I enter something on the first page the second page superimposes on it. that's fine, I'm just trying to learn this, so I was wondering why that would happen.
    thank you thank you thank you!!

  6. #6
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Auto Sort

    That's because you have to stop the screen from udating so it won't show what's happening. Use this:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim LastRow As Long
        Dim ws As Worksheet
        
        Application.ScreenUpdating = False    
        
        Set ws = Sheets(2)
        
        LastRow = ws.UsedRange.Rows.Count
        
        With ws.Sort
            .SortFields.Clear
            .SortFields.Add Key:=Range("C8:C" & LastRow) _
            , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
            .SetRange Range("A8:C" & LastRow)
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        Application.ScreenUpdating = True
        
    End Sub
    Lines added in blue.

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