Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting a range on another worksheet without selecting the worksheet

I have two worksheets, 'Project Rank' and 'WorkOrders'.

The named range 'pick.pn' is one cell located on 'Project Rank' and the
named range 'wo' consists of several rows located on 'WorkOrders'.

The following code works fine from any worksheet in the file:

Sub AutoSort()

Application.Goto Reference:="wo"
Selection.Sort Key1:=Range("AB6"), Order1:=xlAscending, Key2:= _
Range("P6"), Order2:=xlAscending, Key3:=Range("O6"),
Order3:=xlDescending _
, Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
Application.Goto Reference:="pick.pn"

End Sub

But I shouldn't have to use the Application.Goto lines of code should
I?

Why can't the following work (from any worksheet in the file):
Sub AutoSort()

Worksheets("WorkOrders").Range("wo")
Selection.Sort Key1:=Range("AB6"), Order1:=xlAscending, Key2:= _
Range("P6"), Order2:=xlAscending, Key3:=Range("O6"),
Order3:=xlDescending _
, Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
Worksheets("Project Rank").Range("pick.pn")

End Sub

I've tried and I get a Run-time error 1004: Select method of Range
class failed message.

Help appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sorting a range on another worksheet without selecting the worksheet

with worksheets("workorders")
.range("wo").sort _
Key1:=.Range("AB6"), Order1:=xlAscending, _
Key2:=.Range("P6"), Order2:=xlAscending, _
Key3:=.Range("O6"), Order3:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
end with

The dots in front of the ranges refer to the object in the previos with
statement--in this case worksheets("workorders")


wrote:

I have two worksheets, 'Project Rank' and 'WorkOrders'.

The named range 'pick.pn' is one cell located on 'Project Rank' and the
named range 'wo' consists of several rows located on 'WorkOrders'.

The following code works fine from any worksheet in the file:

Sub AutoSort()

Application.Goto Reference:="wo"
Selection.Sort Key1:=Range("AB6"), Order1:=xlAscending, Key2:= _
Range("P6"), Order2:=xlAscending, Key3:=Range("O6"),
Order3:=xlDescending _
, Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
Application.Goto Reference:="pick.pn"

End Sub

But I shouldn't have to use the Application.Goto lines of code should
I?

Why can't the following work (from any worksheet in the file):
Sub AutoSort()

Worksheets("WorkOrders").Range("wo")
Selection.Sort Key1:=Range("AB6"), Order1:=xlAscending, Key2:= _
Range("P6"), Order2:=xlAscending, Key3:=Range("O6"),
Order3:=xlDescending _
, Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
Worksheets("Project Rank").Range("pick.pn")

End Sub

I've tried and I get a Run-time error 1004: Select method of Range
class failed message.

Help appreciated.


--

Dave Peterson
Reply
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
Sorting a range of worksheet tabs A-Z LaDdIe Excel Worksheet Functions 2 February 18th 07 09:47 AM
selecting range and copying to new worksheet shark102 Excel Programming 7 October 20th 05 04:23 PM
Selecting a Worksheet Range Coolboy55 Excel Worksheet Functions 6 August 23rd 05 03:57 PM
selecting cell range in other worksheet without switching to worksheet suzetter[_4_] Excel Programming 4 June 22nd 05 08:55 PM
Selecting a range in a different worksheet Bob Chisholm Excel Programming 2 February 22nd 04 03:46 PM


All times are GMT +1. The time now is 12:00 AM.

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

About Us

"It's about Microsoft Excel"