Andy Ardueser
Andy Ardueser

Reputation: 17

Sorting all worksheets in a workbook at once

I have a workbook with 4 worksheets (Sheet1, Sheet2, ...). The sheets are the same format; the columns are identical variables, but they have different values below. So in theory, they should be able to be sorted in the same way. I've tried to ctrl-select all the tabs, but the Sort option becomes unavailable at that point.

Does anyone know if there's a way to do this without making a different macro for each of the 4 sheets? That seems annoyingly redundant. Any help is appreciated.

Upvotes: 0

Views: 10650

Answers (1)

Derek Cheng
Derek Cheng

Reputation: 525

I assume you are referring to the menu function sort. It doesn't allow user to select cells in different worksheets and sort them. You could implement a For each loop to sort data in each worksheet within the same macro. Something like the following

Sub SortingAllWorksheet()
Dim wsh As Worksheet
For Each wsh In ThisWorkbook.Sheets
    'sort columns A to C based on data in column C
    wsh.Columns("A:C").Sort key1:=Range("C2"), order1:=xlAscending, Header:=xlYes
Next
End Sub

Upvotes: 2

Related Questions