VBA to sort data across multiple worksheets (same range)

DrH100

Board Regular
Joined
Dec 30, 2011
Messages
72
Hi all

As usual I have no idea where to start on this one.

I have a workbook with a number of sheets in that I want to perform a sort on all of them.

I would like to sort the data in A29:K100 (No headers) by column B (ascending) across all worksheets in the workbook. I don't know how many there will be as people may add sheets at any time however the range will always be the same.

Hope that makes sense and as always any help appreciated.
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,059
Try:
Code:
Sub SortSheets()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    For Each ws In Sheets
        ws.Sort.SortFields.Clear
        ws.Sort.SortFields.Add Key:=Range("B29:B100"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ws.Sort
            .SetRange Range("A29:K100")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Last edited:

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
9,059
You are very welcome. :) The macro just loops through all the sheets and sorts each one based on the range you mentioned.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,986
Messages
5,471,823
Members
406,788
Latest member
cmtjack

This Week's Hot Topics

Top