LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Sort Current Worksheet

VBA newbie. I'm sure there's an easier way to write this but I can't
seem to form my question succinctly enough to find the answer.

My code below works perfectly. Except for the fact that my workbook
contains 25 worksheets that I want to sort exactly the same way and
only 3 worksheets I need to sort differently. How can I update the
first argument to say "If ActiveWorksheet.Name < ("Sheet1, Sheet2,
Sheet3, Sheet4, etc. all the way to 22), sort this way; if Active
Worksheet.Name = "Sheet23", sort this way.

Any and all help is tremedously appreciated.

Sub SortCurrent()
If ActiveSheet.Name = "Sheet1" Then

Range("A:L").Sort Key1:=Range("C2"), Order1:=xlAscending,
Key2:=Range _
("D2"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase _
:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal
End If

If ActiveSheet.Name = "Sheet 23" Then

Range("B:C").Sort Key1:=Range("B2"), Order1:=xlAscending,
Key2:=Range _
("C2"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase _
:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal
End If
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort doesn't recognize current region RobWN Excel Worksheet Functions 2 September 7th 07 10:48 PM
'Save current worksheet'; 'Open next worksheet' - two command buttons englishmustard Excel Discussion (Misc queries) 1 April 7th 06 12:54 PM
I want in one worksheet to relatively link to/reference cells in another without changing the format of the current worksheet. [email protected] Excel Discussion (Misc queries) 0 September 22nd 05 04:39 PM
excel change default column sort to current selection john palmer Excel Worksheet Functions 2 March 8th 05 03:07 PM
I want to sort data randomly in addition to the current descendin. ckephart Excel Worksheet Functions 2 November 12th 04 06:11 PM


All times are GMT +1. The time now is 07:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"