+ Reply to Thread
Results 1 to 5 of 5

Select and Sort

Hybrid View

  1. #1
    Registered User
    Join Date
    11-30-2010
    Location
    Warrington
    MS-Off Ver
    Excel 2003
    Posts
    19

    Talking Select and Sort

    Hi All - this ones making me pull my hair out. Googled around alot, but can't find anything to help.

    I've got a sheet which has data copied into col A - L but, col M contains a formula which is right down to r3000 or something.

    I need to put a Macro in place so that it selects all cells starting at A2 and going down to M - whatever the last row is that has data in col A and then stop.

    I then need VBA to sort these cells M Descending and then col K descending.

    I've tried numerous things, but can't get it to work.

    Can you help me? I'm very very new to VBA so excuse my ignorance.

    Thanks

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Select and Sort

    Hello leightjones123,

    This macro should do it.
    Sub SortIt()
    
        Dim Rng As Range
        Dim RngEnd As Range
        Dim Wks As Worksheet
        
            Set Wks = ActiveSheet
            
            Set Rng = Wks.Range("A2:M2")
            Set RngEnd = Wlks.Cells(Rows.Count, Rng.Column).End(xlUp)
            If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
            
                Rng.Sort Key1:=Rng.Cells(1, 13), Order1:=xlDescending, _
                         Key2:=Rng.Cells(1, 11), Order2:=xlDescending, _
                         Header:=xlGuess, MatchCase:=False, _
                         Orientation:=xlTopToBottom, _
                         DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-30-2010
    Location
    Warrington
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Select and Sort

    Perfect! Thanks so much!

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Select and Sort

    Hello leighjones123,

    I take it the macro worked correctly. Should I mark this post as solved?

  5. #5
    Registered User
    Join Date
    11-30-2010
    Location
    Warrington
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Select and Sort

    Yes if you could do,

    Many thanks once again

+ 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