Sorting Excel columns in several worksheets at once.

G

Guest

I have information in several excel worksheets. All worksheets are formated
the same within the file. How do I sort all the worksheets at once by one of
the columns, for instance sort all worksheets by column A.
 
D

Dave Peterson

You could record a macro that sorts the data the way you want. Then run that
same code for each worksheet that you need sorted.

For example, this expects headers in row 1 of each worksheet. It sorts columns
A:G and determines the last row by the last row used in column A.

And it it uses column 1 (A), column 3 (C), and column 5 (E) as the key columns.

Option Explicit
Sub testme01()

Dim myRng As Range
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
With wks
Set myRng = .Range("a1:G" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With

With myRng
.Cells.Sort key1:=.Columns(1), order1:=xlAscending, _
key2:=.Columns(3), order2:=xlAscending, _
key3:=.Columns(5), order3:=xlAscending, _
header:=xlYes
End With
Next wks
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top