Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default How sort my working sheet not the main sheet?



I'm using the function below to sort my worksheet, the problem I'm having is
that everything worked fine until I copied the data to a new "Worksheet" and
want the sort to be done on the new sheet not on the "Mainsheet" even when
the worksheet has the focus the mainsheet is the one being sorted. What do I
need to do?



Function My_Column_Sort(First_Data_Row As Integer, AscendingOrder As
Boolean, _
First_Column As String, Optional Second_Column As
String = "Z", _
Optional Third_Column As String = "Z")

'Allows you to sort the columns in what ever fashion specified. _
using up to Four Columns. Need to build statement in case less then _
four Sort Columns are given.


Range("A" & First_Data_Row & ":AA55550").Sort
Key1:=Range(First_Column & First_Data_Row), _
Order1:=xlAscending, Key2:=Range(Second_Column & First_Data_Row), _
Order2:=xlAscending, Key3:=Range(Third_Column & First_Data_Row), _
Order3:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
'AA55550
End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How sort my working sheet not the main sheet?

If this is in a general module, it will work on the active sheet. If you
have it in a sheet module, then it will sort on the sheet that contains the
code. If you want to specify what sheet, add the sheet as an argument



Function My_Column_Sort(shName as string, _
First_Data_Row As Integer, _
First_Column As String, _
Optional Second_Column As String = "Z", _
Optional Third_Column As String = "Z")

'Allows you to sort the columns in what ever fashion specified. _
'using up to Three Columns. Need to build statement in case less then _
'Three Sort Columns are given

Dim sh as Worksheet
set sh = Worksheets(shName)
sh.Range("A" & First_Data_Row & ":AA55550").Sort _
Key1:=sh.Range(First_Column & First_Data_Row), _
Order1:=xlAscending, Key2:=sh.Range(Second_Column & First_Data_Row),
_
Order2:=xlAscending, Key3:=sh.Range(Third_Column & First_Data_Row), _
Order3:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
'AA55550
End Function

--
Regards,
Tom Ogilvy



"HotRod" wrote in message
...


I'm using the function below to sort my worksheet, the problem I'm having

is
that everything worked fine until I copied the data to a new "Worksheet"

and
want the sort to be done on the new sheet not on the "Mainsheet" even when
the worksheet has the focus the mainsheet is the one being sorted. What do

I
need to do?



Function My_Column_Sort(First_Data_Row As Integer, AscendingOrder As
Boolean, _
First_Column As String, Optional Second_Column As
String = "Z", _
Optional Third_Column As String = "Z")

'Allows you to sort the columns in what ever fashion specified. _
using up to Four Columns. Need to build statement in case less then _
four Sort Columns are given.


Range("A" & First_Data_Row & ":AA55550").Sort
Key1:=Range(First_Column & First_Data_Row), _
Order1:=xlAscending, Key2:=Range(Second_Column & First_Data_Row),

_
Order2:=xlAscending, Key3:=Range(Third_Column & First_Data_Row), _
Order3:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
'AA55550
End Function




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default How sort my working sheet not the main sheet?

Hi,
Something like (assuming you calling the function from VBA):

Dim ws as worksheet

Set ws=Worksheets("MyWorkSheet") ' whatever worksheet you are sorting ...

My_Column_Sort(ws, ..... ' Add ws as parameter to your function

and the qualify range :

ws.Range("A" & First_Data_Row & ":AA55550").Sort

HTH

"HotRod" wrote:



I'm using the function below to sort my worksheet, the problem I'm having is
that everything worked fine until I copied the data to a new "Worksheet" and
want the sort to be done on the new sheet not on the "Mainsheet" even when
the worksheet has the focus the mainsheet is the one being sorted. What do I
need to do?



Function My_Column_Sort(First_Data_Row As Integer, AscendingOrder As
Boolean, _
First_Column As String, Optional Second_Column As
String = "Z", _
Optional Third_Column As String = "Z")

'Allows you to sort the columns in what ever fashion specified. _
using up to Four Columns. Need to build statement in case less then _
four Sort Columns are given.


Range("A" & First_Data_Row & ":AA55550").Sort
Key1:=Range(First_Column & First_Data_Row), _
Order1:=xlAscending, Key2:=Range(Second_Column & First_Data_Row), _
Order2:=xlAscending, Key3:=Range(Third_Column & First_Data_Row), _
Order3:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
'AA55550
End Function



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default How sort my working sheet not the main sheet?

You just need to designate the worksheet and the range
Worked in Excel 2000

With Sheets("Sheet2").Range("A1:A15")
.Sort Key1:=Sheets("Sheet2").Range("A1"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With


--
steveB

Remove "AYN" from email to respond
"HotRod" wrote in message
...


I'm using the function below to sort my worksheet, the problem I'm having
is that everything worked fine until I copied the data to a new
"Worksheet" and want the sort to be done on the new sheet not on the
"Mainsheet" even when the worksheet has the focus the mainsheet is the one
being sorted. What do I need to do?



Function My_Column_Sort(First_Data_Row As Integer, AscendingOrder As
Boolean, _
First_Column As String, Optional Second_Column As
String = "Z", _
Optional Third_Column As String = "Z")

'Allows you to sort the columns in what ever fashion specified. _
using up to Four Columns. Need to build statement in case less then _
four Sort Columns are given.


Range("A" & First_Data_Row & ":AA55550").Sort
Key1:=Range(First_Column & First_Data_Row), _
Order1:=xlAscending, Key2:=Range(Second_Column & First_Data_Row), _
Order2:=xlAscending, Key3:=Range(Third_Column & First_Data_Row), _
Order3:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
'AA55550
End Function



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default How sort my working sheet not the main sheet?

Thanks a bunch.

I think this original sort may actually have came from Tom, not sure
though...





"HotRod" wrote in message
...


I'm using the function below to sort my worksheet, the problem I'm having
is that everything worked fine until I copied the data to a new
"Worksheet" and want the sort to be done on the new sheet not on the
"Mainsheet" even when the worksheet has the focus the mainsheet is the one
being sorted. What do I need to do?



Function My_Column_Sort(First_Data_Row As Integer, AscendingOrder As
Boolean, _
First_Column As String, Optional Second_Column As
String = "Z", _
Optional Third_Column As String = "Z")

'Allows you to sort the columns in what ever fashion specified. _
using up to Four Columns. Need to build statement in case less then _
four Sort Columns are given.


Range("A" & First_Data_Row & ":AA55550").Sort
Key1:=Range(First_Column & First_Data_Row), _
Order1:=xlAscending, Key2:=Range(Second_Column & First_Data_Row), _
Order2:=xlAscending, Key3:=Range(Third_Column & First_Data_Row), _
Order3:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
'AA55550
End Function



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
Auto filter sort ascending not working while sheet protected TommyB Excel Worksheet Functions 6 March 17th 10 02:51 PM
adding new data to another sheet from the main sheet ycwkpp898 Excel Discussion (Misc queries) 1 January 6th 09 04:16 PM
Summarizing data on one main sheet Cali00 Excel Worksheet Functions 0 April 20th 06 03:03 AM
How do I combine data from several sheets into one main sheet? Caren F Excel Worksheet Functions 0 April 19th 06 06:39 PM
Selection from list on main sheet from suplemental sheet in same w Kelly New Users to Excel 1 August 12th 05 04:37 PM


All times are GMT +1. The time now is 04:51 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"