VBA to sort data across multiple worksheets (same range)

DrH100

Board Regular
Joined
Dec 30, 2011
Messages
78
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.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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:
Upvote 0
You are very welcome. :) The macro just loops through all the sheets and sorts each one based on the range you mentioned.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top