Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

sorting data multiple tabs

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Sorting Data on Multiple Tabs

Sorting Data on Multiple Tabs

ResolvedVersion 2010

Mark has attended:
Excel VBA Intro Intermediate course
Excel Advanced - For Power Users course
Excel PowerPivot course
Excel Dashboards for Business Intelligence course

Sorting Data on Multiple Tabs

I've written the following sub routine to sort a data set on one tab and then move onto the next tab and sort another data set. The data set is the same size and takes up exactly the same cells on all tabs. It's sorting on one tab but not moving onto the next.

Help?



Sub Sort()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets

Range("A16:E163").Select
Range("A163").Activate
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range("E16:E163"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange Range("A16:E163")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A4").Select

Next ws

End Sub

RE: Sorting Data on Multiple Tabs

Hi Mark,

Thank you for the forum question.

You are very very close.

You are only missing one thing in the code. You are not changing the active sheet. If you after the loop enter ws.select the code will run through all sheets in the workbook (see below).
Sub Sort()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.Select
Range("b3") = 3

Range("A16:E163").Select
Range("A163").Activate
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Key:=Range("E16:E163"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange Range("A16:E163")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A4").Select

Next ws

End Sub

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Mon 27 Apr 2015: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Hide separate columns in Excel 2010

If you want to hide columns not adjacent to each other for example, Columns A, C and E then:-

1) Click on the fist column to be hidden i.e. A

2) Press and hold down the CTRL key

3) While holding the CTRL key, left click on the rest of the columns you want to hide i.e. C and E

4) Right click and choose Hide

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.26 secs.