+ Reply to Thread
Results 1 to 39 of 39

Sort column 2 different ways.

Hybrid View

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

    Re: Sort column 2 different ways.

    Try:

    Sub brainzlp()
    Dim i As Long, r As Range, x As Long
    x = Range("A" & Rows.Count).End(3).Row
    Range(Cells(7, 1), Cells(x, ActiveSheet.UsedRange.Columns.Count)).Sort Key1:=Range("M7"), Order1:=xlDescending, Key2:=Range("P7"), Order2:=xlAscending, Key3:=Range("X7"), Order3:=xlAscending
    Set r = Columns(13).Find("SIM", LookIn:=xlValues, lookat:=xlWhole)
        If r Is Nothing Then
        GoTo zz
        Else
        Set r = Nothing
    Set r = Columns(13).Find("NÃO", LookIn:=xlValues, lookat:=xlWhole)
        If Not r Is Nothing Then
        Range(Cells(7, 1), Cells(r.Row - 1, ActiveSheet.UsedRange.Columns.Count)).Sort Key1:=Range("P" & r.Row - 1), Order1:=xlAscending, Key2:=Range("X" & r.Row - 1), Order1:=xlAscending
        Range(Cells(r.Row, "A"), Cells(x, ActiveSheet.UsedRange.Columns.Count)).Sort Key1:=Cells(r.Row, "X"), Order1:=xlAscending
        End If
    Set r = Nothing
    End If
    zz:
    
        
    End Sub

  2. #2
    Forum Contributor
    Join Date
    07-20-2015
    Location
    Covilhã
    MS-Off Ver
    2010
    Posts
    516

    Re: Sort column 2 different ways.

    Hello Mr. John,

    I've tried but it doesn't sort nothing any "SIM" values.

    I'll opt for this, although it's
    On Error Resume Next
    
    Dim i As Long, r As Range, x As Long
    x = Range("A" & Rows.Count).End(3).Row
    Range(Cells(7, 1), Cells(x, ActiveSheet.UsedRange.Columns.Count)).Sort Key1:=Range("M7"), Order1:=xlDescending, Key2:=Range("P7"), Order2:=xlAscending, Key3:=Range("X7"), Order3:=xlAscending
    Set r = Columns(13).Find("NÃO", LookIn:=xlValues, lookat:=xlWhole)
        If Not r Is Nothing Then
        Range(Cells(7, 1), Cells(r.Row - 1, ActiveSheet.UsedRange.Columns.Count)).Sort Key1:=Range("P" & r.Row - 1), Order1:=xlAscending, Key2:=Range("X" & r.Row - 1), Order1:=xlAscending
        Range(Cells(r.Row, "A"), Cells(x, ActiveSheet.UsedRange.Columns.Count)).Sort Key1:=Cells(r.Row, "X"), Order1:=xlAscending
        End If
    Set r = Nothing
    On Error GoTo 0

+ 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. Replies: 1
    Last Post: 03-04-2015, 02:57 PM
  2. [SOLVED] I have a sort macro. How to add script to preselect rows to sort based on column value?
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-09-2014, 02:25 AM
  3. Replies: 2
    Last Post: 01-15-2014, 09:31 AM
  4. [SOLVED] Move currency symbol into another column by Regex or by other ways
    By taps in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2013, 06:16 AM
  5. Can you sort a pivot field two ways?
    By cch70 in forum Excel General
    Replies: 1
    Last Post: 03-09-2011, 07:08 PM
  6. Replies: 3
    Last Post: 05-17-2009, 04:31 AM
  7. Formula Reference Row To Column, Scroll Ways!
    By rr1050 in forum Excel General
    Replies: 4
    Last Post: 01-05-2009, 07:54 AM

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