Sort column ascending on many worksheets

  • Thread starter Thread starter tkincaid
  • Start date Start date
T

tkincaid

i have over 100 worksheets and it will grow, they all have the same columns.
I want to make a macro that will sort each worksheet via column B with dates.

A B C

all 12/8/08 all-t-08-e-001

The columns continue until H and go to line 98.


Thank You
 
Hi

This macro will sort all sheets based on column B, assuming you have
headings in row 1.

Sub SortSheets()
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Sheets
Columns("A:H").Sort Key1:=Range("B1"), Order1:=xlAscending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Next
Application.ScreenUpdating = True
End Sub

Regards,
Per
 
Do you want every sheet sorted or are there some sheets that you want
skipped? HTH Otto
 
For Each sht In Sheets

sht.Cells.Sort _
Key1:=sht.Range("B1"), _
Order1:=xlAscending, _
Header:=xlGuess

Next sht
 
I copied this and it didn't work, and I do have headings in row 1 all my
information starts on line 3 column a all the way to J 98, but I want to sort
via column B which is the date.

Sorry for the post, it told me it didn't send, but it did.
 
Try this:

Sub SortSheets()
Dim sh
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Sheets
Range("A3:J98").Sort Key1:=Range("B3"), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
Next
Application.ScreenUpdating = True
End Sub

Regards,
Per
 
this works, but only if I am on the sheet, I want to run a macro after all
data is entered and run it once to do all sheets.

thanks
 
My fault :-(

This will sort all sheets at once.

Sub SortSheets()
Dim sh
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Sheets
With sh
.Range("A3:J98").Sort Key1:=.Range("B3"), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
End With
Next
Application.ScreenUpdating = True
End Sub

Regards,
Per
 

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

Back
Top