+ Reply to Thread
Results 1 to 19 of 19

Sort rows in a workbook based on Date in Row A

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Sort rows in a workbook based on Date in Row A

    This sounds very simple, however i have searched many forums and tried various codes but without sucess, my data spreads from Columns A to R and starts in row 4.

    Would be grateful if someone could help me with the code to sort the data by column A

    many thanks

  2. #2
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Sort rows in a workbook based on Date in Row A

    Hi michelle..

    below is just a recorded macro.. check this..

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A4")
        With ActiveWorkbook.Worksheets("Sheet1").Sort
            .SetRange Range("A4").CurrentRegion
            .Apply
        End With
    End Sub
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  3. #3
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Sort rows in a workbook based on Date in Row A

    Thanks Debraj for your prompt response. Does this mean i need a button as i was hoping for it to apply automatically upon opening.

  4. #4
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Sort rows in a workbook based on Date in Row A

    OK.. You want this automatically upon opening .. then..

    in ThisWorkbook Section.. in Workbook_Open() use below code..
    Private Sub Workbook_Open()
    Worksheets("Sheet1").Sort.SortFields.Clear
    Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A4")
        With Worksheets("Sheet1").Sort
            .SetRange Range("A4").CurrentRegion
            .Apply
        End With
    End Sub

  5. #5
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Sort rows in a workbook based on Date in Row A

    Hi Debraj, i am receiving a Runtime error 9 subscript out of range, any ideas?

  6. #6
    Registered User
    Join Date
    07-10-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Sort rows in a workbook based on Date in Row A

    Try this,

    Private Sub Workbook_Open()
        Dim lr As Long
        Dim mr As Long
        lr = Worksheets("Partial Shifts").Range("A" & Rows.Count).End(xlUp).Row
        mr = Worksheets("Day Off Trades").Range("A" & Rows.Count).End(xlUp).Row
    
        ActiveWorkbook.Worksheets("Partial Shifts").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Partial Shifts").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Partial Shifts").Sort
            .SetRange Range("A1:L" & lr)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        ActiveWorkbook.Worksheets("Day Off Trades").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Day Off Trades").Sort.SortFields.Add Key:=Range( _
            "A2:A" & mr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Day Off Trades").Sort
            .SetRange Range("A1:L" & mr)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
    End Sub

  7. #7
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Sort rows in a workbook based on Date in Row A

    Hi thanks for responding.

    I was googling this as we speak without any luck, I Assume I need to change "Partial Shifts" and "Day off Trades" are these the tab names? I have 12 tabs - January to February. Appologies for asking a silly question but i am new to this. My Worksheet is called Events Spreadsheet.

    Really appreciate your help.

  8. #8
    Registered User
    Join Date
    07-10-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Sort rows in a workbook based on Date in Row A

    Yes "Partial Shifts" and  "Day off Trades" are worksheets name.
    If you want 12 tab then you have to create 12 objects for each one.

  9. #9
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Sort rows in a workbook based on Date in Row A

    Thank you so much, i have my header in Row 3 and it is placing the data above this, what part of the code do i need to ammend? really really appreciate your help.

  10. #10
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Sort rows in a workbook based on Date in Row A

    Would you mind checking my code, i guessed based on what you gave me. It actually works fine, however i get an error message saying excel found unreadable content this appeared after i entered the code, if i click on yes this is from a trusted source its fine and sorts perfectly but obviously i have done something wrong?!

    private Sub Workbook_Open()
        Dim lr As Long
        Dim mr As Long
        Dim PR As Long
        Dim QR As Long
        Dim RR As Long
        Dim SR As Long
        Dim TR As Long
        Dim UR As Long
        Dim VR As Long
        Dim XR As Long
        Dim YR As Long
        Dim ZR As Long
        
        lr = Worksheets("January").Range("A" & Rows.Count).End(xlUp).Row
        mr = Worksheets("February").Range("A" & Rows.Count).End(xlUp).Row
        PR = Worksheets("March").Range("A" & Rows.Count).End(xlUp).Row
        QR = Worksheets("April").Range("A" & Rows.Count).End(xlUp).Row
        RR = Worksheets("May").Range("A" & Rows.Count).End(xlUp).Row
        SR = Worksheets("June").Range("A" & Rows.Count).End(xlUp).Row
        TR = Worksheets("July").Range("A" & Rows.Count).End(xlUp).Row
        UR = Worksheets("August").Range("A" & Rows.Count).End(xlUp).Row
        VR = Worksheets("September").Range("A" & Rows.Count).End(xlUp).Row
        XR = Worksheets("October").Range("A" & Rows.Count).End(xlUp).Row
        YR = Worksheets("November").Range("A" & Rows.Count).End(xlUp).Row
        ZR = Worksheets("December").Range("A" & Rows.Count).End(xlUp).Row
        
        ActiveWorkbook.Worksheets("January").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("January").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("January").Sort
            .SetRange Range("A1:R" & lr)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        ActiveWorkbook.Worksheets("February").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("February").Sort.SortFields.Add Key:=Range( _
            "A2:A" & mr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("February").Sort
            .SetRange Range("A1:R" & mr)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
            
        End With
        ActiveWorkbook.Worksheets("March").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("March").Sort.SortFields.Add Key:=Range( _
            "A2:A" & PR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("March").Sort
            .SetRange Range("A1:R" & PR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        ActiveWorkbook.Worksheets("April").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("April").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("April").Sort
            .SetRange Range("A1:R" & QR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
         ActiveWorkbook.Worksheets("May").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("May").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("May").Sort
            .SetRange Range("A1:R" & RR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
          
        ActiveWorkbook.Worksheets("June").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("June").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("June").Sort
            .SetRange Range("A1:R" & SR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        ActiveWorkbook.Worksheets("July").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("July").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("July").Sort
            .SetRange Range("A1:R" & TR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        ActiveWorkbook.Worksheets("August").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("August").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("August").Sort
            .SetRange Range("A1:R" & UR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        ActiveWorkbook.Worksheets("September").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("September").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("September").Sort
            .SetRange Range("A1:R" & VR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
                    
        End With
        
        ActiveWorkbook.Worksheets("October").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("October").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("October").Sort
            .SetRange Range("A1:R" & XR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        ActiveWorkbook.Worksheets("November").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("November").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("November").Sort
            .SetRange Range("A1:R" & YR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
         ActiveWorkbook.Worksheets("December").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("December").Sort.SortFields.Add Key:=Range( _
            "A2:A" & lr), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("December").Sort
            .SetRange Range("A1:R" & ZR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
    End Sub

  11. #11
    Registered User
    Join Date
    07-10-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Sort rows in a workbook based on Date in Row A

    if you want to add worksheet automatically then use this code

    Dim NewSheet As Worksheet 
    Set NewSheet = Sheets.Add 
     
    NewSheet.Name = "NewSheetName"

  12. #12
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Sort rows in a workbook based on Date in Row A

    Hi thanks again for replying.

    I am really sorry to ask but where do i insert the code and what part of my code do i need to remove, i really am very new to this and willing to learn.

  13. #13
    Registered User
    Join Date
    07-10-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Sort rows in a workbook based on Date in Row A

    You don't need to declare 12 object for 12 months saperately you just add the above code that I given to you that add worksheet automatically to your workbook.
    That code you have to place within the loop.

    Look at this sample code:

    Function SectorSheet()
    
        Dim InputWorkBk As Workbook    
        Dim InpWS As String
        Dim InpCounter As Integer
        Dim EndRowS As Integer
        Dim InputSheet As String
        Dim InWS As String
        Dim OutCounter As String
        Dim InpCount As String
        
        InputSheet = "SectorTemplate"
        InpWS = "SectorDetails"
        InWS = "DrillDown_Attribution"
        
        InputWorkBk.Worksheets(InpWS).Select
        InputWorkBk.Worksheets(InpWS).Range("A2").Select
        Selection.End(xlDown).Select
        EndRowS = ActiveCell.Row
        
        InpCounter = 2
        
        
        Do Until InputWorkBk.Worksheets(InpWS).Range("A" & InpCounter).Value = ""
        
            If InputWorkBk.Worksheets(InpWS).Range("O" & InpCounter).Value = "1" Then
                
                NewSheetName = InputWorkBk.Worksheets(InpWS).Range("A" & InpCounter).Value
                InputWorkBk.Worksheets(InputSheet).Copy After:=Sheets(Sheets.Count)
                ActiveSheet.Name = NewSheetName
                
                InputWorkBk.Worksheets(NewSheetName).Range("A3").Value = NewSheetName
                
            End If
                
                InpCount = 9
                OutCounter = 3
                
        Do Until InputWorkBk.Worksheets(InWS).Range("A" & InpCount).Value = ""
            
            If InputWorkBk.Worksheets(InWS).Range("A" & InpCount).Value = NewSheetName Then
                    
            If InputWorkBk.Worksheets(InWS).Range("B" & InpCount).Value <> "" Then
            
                If OutCounter < EndRowS Then
                    
                    InputWorkBk.Worksheets(NewSheetName).Range("O" & OutCounter).Value = InputWorkBk.Worksheets(InWS).Range("B" & InpCount).Value
                    InputWorkBk.Worksheets(NewSheetName).Range("P" & OutCounter).Value = InputWorkBk.Worksheets(InWS).Range("J" & InpCount).Value
                    InputWorkBk.Worksheets(NewSheetName).Range("Q" & OutCounter).Value = InputWorkBk.Worksheets(InWS).Range("K" & InpCount).Value
                    InputWorkBk.Worksheets(NewSheetName).Range("R" & OutCounter).Value = InputWorkBk.Worksheets(InWS).Range("L" & InpCount).Value
                    InputWorkBk.Worksheets(NewSheetName).Range("S" & OutCounter).Value = InputWorkBk.Worksheets(InWS).Range("H" & InpCount).Value
                    
                    OutCounter = OutCounter + 1
                
                End If
                
            End If
            
            End If
            
            InpCount = InpCount + 1
        
        Loop
                
            InpCounter = InpCounter + 1
        
        Loop
    
    End Function
    I hope you understand.

  14. #14
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Sort rows in a workbook based on Date in Row A

    Hi, as i said i am a real newbie i cant read the code but i have been playing around wth it for an hour and a half. I have the following, i have been adapting your code to the sample code, am i on the right tracks??

    Private Sub Workbook_Open()
        Dim lr As Long
        Dim mr As Long
        Dim NewSheet As Worksheet
        Set NewSheet = Sheets.Add
     
    NewSheet.Name = "NewSheetName"
        
        
        Do Until Eventsspreadsheet.WorkBk = Worksheets("January").Range("A" & Rows.Count).End(xlUp).Row
        
       NewSheetName = Eventsspreadsheet.WorkBk.Worksheets("January").Range("A" & Rows.Count).End(xlUp).Row
                Eventsspreadsheetworkbk.Worksheets(February).Copy After:=Sheets(Sheets.Count)
                ActiveSheet.Name = February
                Eventsspreadsheetworkbk.Worksheets(February).Range("A" & Rows.Count).End(xlUp).Row = February
                
                End If
                
               Do Until Eventsspreadsheet.WorkBk = Worksheets("March").Range("A" & Rows.Count).End(xlUp).Row
    
    If Eventsspreadsheet.WorkBk = Worksheets("March").Range("A" & Rows.Count).End(xlUp).Row = April Then
    I think i need settig straight with what i have and then i will have another go, i am self teaching so do not understand the terminology of the code.

    Thansk for helping me get my head round it. (Sorry reposted with code tags and not HTML!)

  15. #15
    Registered User
    Join Date
    07-10-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Sort rows in a workbook based on Date in Row A

    you done wrong man.

    I attached image with this post.

    check it.

    code.JPG

  16. #16
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Sort rows in a workbook based on Date in Row A

    Thanks for your reply and the code explanation. My code knowledge is very basic and therfore i am unable to interpret the information you are giving me. Im not sure what i need to change/add on your sample. I will have to leave it and manually sort my data on each tab as i really do not understand how to write it from what you have provided.

    Thanks for your patience.

  17. #17
    Registered User
    Join Date
    07-10-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Sort rows in a workbook based on Date in Row A

    I send you the sample code. check this.

    run this code and see the output.
    Attached Files Attached Files
    Last edited by ankitparate; 07-11-2013 at 09:44 AM.

  18. #18
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Sort rows in a workbook based on Date in Row A

    I have done it i fiddled around with what i was doing and it works, admittedly its probably not pretty but it does the job. Thansk so much for your patience and help.

    Private Sub workbook_open()
    
     Range("A2:R215").Select
        ActiveWorkbook.Worksheets("January").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("January").sort.SortFields.Add Key:=Range("A2:A215" _
            ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("January").sort
            .SetRange Range("A2:R215")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
          Range("A2:R217").Select
        ActiveWorkbook.Worksheets("February").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("February").sort.SortFields.Add Key:=Range( _
            "A2:A217"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("February").sort
            .SetRange Range("A1:R217")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A2:R215").Select
        ActiveWorkbook.Worksheets("March").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("March").sort.SortFields.Add Key:=Range("A2:A215" _
            ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("March").sort
            .SetRange Range("A2:R215")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
            Range("A2:R217").Select
        ActiveWorkbook.Worksheets("April").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("April").sort.SortFields.Add Key:=Range( _
            "A2:A217"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("April").sort
            .SetRange Range("A1:R217")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A2:R215").Select
        ActiveWorkbook.Worksheets("May").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("May").sort.SortFields.Add Key:=Range("A2:A215" _
            ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("May").sort
            .SetRange Range("A2:R215")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
            Range("A2:R217").Select
        ActiveWorkbook.Worksheets("June").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("June").sort.SortFields.Add Key:=Range( _
            "A2:A217"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("June").sort
            .SetRange Range("A1:R217")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        Range("A2:R215").Select
        ActiveWorkbook.Worksheets("July").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("July").sort.SortFields.Add Key:=Range("A2:A215" _
            ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("July").sort
            .SetRange Range("A2:R215")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
            Range("A2:R217").Select
        ActiveWorkbook.Worksheets("August").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("August").sort.SortFields.Add Key:=Range( _
            "A2:A217"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("August").sort
            .SetRange Range("A1:R217")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A2:R215").Select
        ActiveWorkbook.Worksheets("September").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("September").sort.SortFields.Add Key:=Range("A2:A215" _
            ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("September").sort
            .SetRange Range("A2:R215")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
           Range("A2:R217").Select
        ActiveWorkbook.Worksheets("October").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("October").sort.SortFields.Add Key:=Range( _
            "A2:A217"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("October").sort
            .SetRange Range("A1:R217")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Range("A2:R215").Select
        ActiveWorkbook.Worksheets("November").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("November").sort.SortFields.Add Key:=Range("A2:A215" _
            ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("November").sort
            .SetRange Range("A2:R215")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
           Range("A2:R217").Select
        ActiveWorkbook.Worksheets("December").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("December").sort.SortFields.Add Key:=Range( _
            "A2:A217"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("December").sort
            .SetRange Range("A1:R217")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
       End With
        
       End Sub

  19. #19
    Registered User
    Join Date
    07-10-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Sort rows in a workbook based on Date in Row A

    Anytime.

    If you want more help then ask me

+ 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