+ Reply to Thread
Results 1 to 4 of 4

AutoSort based on 2 columns. Auto refresh without clicking on data

Hybrid View

Declamatory AutoSort based on 2 columns. ... 02-25-2016, 12:02 PM
ppgab Re: AutoSort based on 2... 02-25-2016, 12:42 PM
Declamatory Re: AutoSort based on 2... 02-26-2016, 03:57 AM
ppgab Re: AutoSort based on 2... 02-26-2016, 11:28 AM
  1. #1
    Forum Contributor
    Join Date
    03-09-2012
    Location
    Isle of Man
    MS-Off Ver
    Excel 2010
    Posts
    118

    AutoSort based on 2 columns. Auto refresh without clicking on data

    Hi Folks,

    I have some code that sorts data in range S2:Z10. The data is sorted first by column Y then by column U.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim Rng As Range
        
            Set Rng = Intersect(Target, Range("Y1:Y10"))
            If Rng Is Nothing Then Exit Sub
            
            Rng.Sort Key1:=Range("Y2"), Order1:=xlAscending, _
                     Key2:=Range("U2"), Order2:=xlAscending, _
                     Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
                     Orientation:=xlTopToBottom, _
                     DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
    
    End Sub
    The problem is that all of the data in that range is pulled through from other worksheets. This means that the data changes but it doesn't sort it until I double click on a cell in the range and hit enter. Is there anyway to get the range to auto sort when the data in the range changes even though no it actually clicking on any cell in the range and hitting enter.

    Thanks in advance.

    Dec

  2. #2
    Registered User
    Join Date
    06-03-2014
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    52

    Re: AutoSort based on 2 columns. Auto refresh without clicking on data

    Quote Originally Posted by Declamatory View Post
    Hi Folks,

    I have some code that sorts data in range S2:Z10. The data is sorted first by column Y then by column U.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim Rng As Range
        
            Set Rng = Intersect(Target, Range("Y1:Y10"))
            If Rng Is Nothing Then Exit Sub
            
            Rng.Sort Key1:=Range("Y2"), Order1:=xlAscending, _
                     Key2:=Range("U2"), Order2:=xlAscending, _
                     Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
                     Orientation:=xlTopToBottom, _
                     DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
    
    End Sub
    The problem is that all of the data in that range is pulled through from other worksheets. This means that the data changes but it doesn't sort it until I double click on a cell in the range and hit enter. Is there anyway to get the range to auto sort when the data in the range changes even though no it actually clicking on any cell in the range and hitting enter.

    Thanks in advance.

    Dec
    You need to provide more info, there's no way to visualize what you're describing

  3. #3
    Forum Contributor
    Join Date
    03-09-2012
    Location
    Isle of Man
    MS-Off Ver
    Excel 2010
    Posts
    118

    Post Re: AutoSort based on 2 columns. Auto refresh without clicking on data

    Sorry ppgab,

    We have a team that plays in a league. The players play singles games and doubles games. Players are ranked according to their singles results.

    The data below is in columns S to Z in a sheet called results. The data is sorted by the singles rank in column Y. The data in column Y is arrived at by looking at column T first and then column U (The % stats of wins vs losses).

    Each player has their own worskheet in the workbook with their stats in. This information feeds into Range S2 to Z10 in the results worksheet i.e. nobody types into the range. It is updated automatically.

    The vba code was intended to sort the data in the range into Singles Rank order when the data is column Y was updated. The vba code does work but only when I double click in one of the cells in the range and hit enter. Because nobody physically types anything into the range it isn't sorting when the data in the range is updated because of new information being inout to each players worksheet.

    I was looking to see if there was a way for the sort to happen automatically.

    Thanks

    Dec
    Attached Images Attached Images

  4. #4
    Registered User
    Join Date
    06-03-2014
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    52

    Re: AutoSort based on 2 columns. Auto refresh without clicking on data

    Ah ok, now I understand, it would be easier if you could attach the worksheet for me to test.

    But here are some things you can try :

    VBA codes to force update (try one at a time at the end of your macro)
    Application.Calculate
    Application.CalculateFull
    Application.CalculateFullRebuild
    ActiveWorkbook.RefreshAll
    DoEvents
    Or, depending on your Excel knowledge, instead make a pivot table that will rank the players, and put this at the end of the macro to refresh the pivot table

    Set pt = ActiveSheet.PivotTables("MyPivot")
    
        pt.RefreshTable
    Sorting a regular table through VBA tends to be problematic

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] auto-fill columns based on data in different columns
    By dawondr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2015, 06:44 PM
  2. Auto Refresh Sheet on Clicking ActiveX Checkbox
    By jcopier in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2015, 01:46 PM
  3. Replies: 2
    Last Post: 12-20-2013, 04:03 PM
  4. Auto populate a third cell, based on data from two columns
    By 12ogboy78 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 03-25-2013, 02:21 AM
  5. Stop columns resizing when Pivots auto refresh on open?
    By drdavidge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-29-2007, 12:14 PM
  6. How can I auto-refresh auto-filters when data changes?
    By Mike@MPWco in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-04-2006, 07:55 AM
  7. Auto fill Column based on data in other columns
    By SITCFanTN in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 06-06-2006, 04:10 PM

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