Consulting

Results 1 to 5 of 5

Thread: Solved: Sort All sheets in a workbook

  1. #1

    Solved: Sort All sheets in a workbook

    Hi
    I have below code, which I expect to sort all the sheets in a workbook, however its not working in all worksheets.

    Please help me in rectifying this code.
    [VBA]
    Sub Sorty()
    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets

    With Range("E1").Select
    Range("A:Z").Sort Key1:=Range("E2"), Order1:=xlAscending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    End With
    On Error Resume Next


    Next ws
    End Sub
    [/VBA]

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    [vba]
    Sub Sorty()
    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets

    ws.Select
    Range("A:Z").Sort Key1:=Range("E2"), Order1:=xlAscending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    On Error Resume Next


    Next ws
    End Sub
    [/vba]

  3. #3
    Thank you very much Patel, code is working as intended, however I made little change

    instead of
    [VBA]
    ws.select
    [/VBA]


    [VBA]
    ws.activate
    [/VBA]

  4. #4
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    why ?

  5. #5
    Hi Patel,

    with "ws.Select" code was sorting only one sheet, not all the sheets,

    hence I tried "ws.activate" which worked as intended

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •