Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
sorting on a non active sheet
I feel very foolish asking this question but I have been going round and
round on this too long. I have the following code in a Userform (not in a module): Sheets(1).Activate Sheets(1).Range(Cells(3,1),Cells(15,20)).Select Selection.sort Key1:=Range(A2), Order1:=xlAscending _ , Key2:=Range(D2), Order2:=xlAscending _ , Header:=xlGuess, OrderCustom:=1, MatchCase:=False _ , Orientation:xlTopToBottom The code works fine. However, I now want to do the sort without activating sheet(1). I have tried all kinds of ways to do the ranges without using selection but to no avail. I went thru the postings and could not find another posting close to this. Can someone help me. -- russ |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
sorting on a non active sheet
Try this... I have changed Header:=xlGuess to xlYes instead of letting XL
make a guess on your behalf... Sheets(1).Range("A3:T15").Sort Key1:=Range("A2"), _ Order1:=xlAscending, _ Key2:=Range("D2"), _ Order2:=xlAscending, _ Header:=xlYes, _ OrderCustom:=1, _ MatchCase:=False -- HTH... Jim Thomlinson "Russ" wrote: I feel very foolish asking this question but I have been going round and round on this too long. I have the following code in a Userform (not in a module): Sheets(1).Activate Sheets(1).Range(Cells(3,1),Cells(15,20)).Select Selection.sort Key1:=Range(A2), Order1:=xlAscending _ , Key2:=Range(D2), Order2:=xlAscending _ , Header:=xlGuess, OrderCustom:=1, MatchCase:=False _ , Orientation:xlTopToBottom The code works fine. However, I now want to do the sort without activating sheet(1). I have tried all kinds of ways to do the ranges without using selection but to no avail. I went thru the postings and could not find another posting close to this. Can someone help me. -- russ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
sorting on a non active sheet
with sheets(1)
with .range(.cells(3,1),.cells(15,20)) .cells.sort Key1:=.columns(1), Order1:=xlAscending, _ Key2:=.columns(3), Order2:=xlAscending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:xlTopToBottom end with end with Notice all the dots (like .cells()). That means that that thing belongs to the object in the previous With statement. And I agree with Jim's tip about not letting xl guess (about headers). You know if you have them or not. Put that in your code (xlyes or xlno). And sheets(1) will be the left most sheet. I'd use the name: with sheets("mysheetnamehere") if I knew it. Russ wrote: I feel very foolish asking this question but I have been going round and round on this too long. I have the following code in a Userform (not in a module): Sheets(1).Activate Sheets(1).Range(Cells(3,1),Cells(15,20)).Select Selection.sort Key1:=Range(A2), Order1:=xlAscending _ , Key2:=Range(D2), Order2:=xlAscending _ , Header:=xlGuess, OrderCustom:=1, MatchCase:=False _ , Orientation:xlTopToBottom The code works fine. However, I now want to do the sort without activating sheet(1). I have tried all kinds of ways to do the ranges without using selection but to no avail. I went thru the postings and could not find another posting close to this. Can someone help me. -- russ -- Dave Peterson |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
sorting on a non active sheet
Oh Dave you don't know how long I worked on this one. I can't thank you
enough. As an aside - I do always use sheets("mysheet") but for illustration purposes i used sheets(1) in my sample code. Where I got all tangled up was trying to find the alternative for key1:=Range("A2") - i had not tried key1:=.columns(1). What would amateurs like me do without you guys. Thanks again. -- russ "Dave Peterson" wrote: with sheets(1) with .range(.cells(3,1),.cells(15,20)) .cells.sort Key1:=.columns(1), Order1:=xlAscending, _ Key2:=.columns(3), Order2:=xlAscending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:xlTopToBottom end with end with Notice all the dots (like .cells()). That means that that thing belongs to the object in the previous With statement. And I agree with Jim's tip about not letting xl guess (about headers). You know if you have them or not. Put that in your code (xlyes or xlno). And sheets(1) will be the left most sheet. I'd use the name: with sheets("mysheetnamehere") if I knew it. Russ wrote: I feel very foolish asking this question but I have been going round and round on this too long. I have the following code in a Userform (not in a module): Sheets(1).Activate Sheets(1).Range(Cells(3,1),Cells(15,20)).Select Selection.sort Key1:=Range(âœA2â), Order1:=xlAscending _ , Key2:=Range(âœD2â), Order2:=xlAscending _ , Header:=xlGuess, OrderCustom:=1, MatchCase:=False _ , Orientation:xlTopToBottom The code works fine. However, I now want to do the sort without activating sheet(1). I have tried all kinds of ways to do the ranges without using selection but to no avail. I went thru the postings and could not find another posting close to this. Can someone help me. -- russ -- Dave Peterson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
sorting on a non active sheet
Thanks Jim - i incorporated your suggestion in the code that Dave Peterson
posted and the combination worked just great. Many thanks. -- russ "Jim Thomlinson" wrote: Try this... I have changed Header:=xlGuess to xlYes instead of letting XL make a guess on your behalf... Sheets(1).Range("A3:T15").Sort Key1:=Range("A2"), _ Order1:=xlAscending, _ Key2:=Range("D2"), _ Order2:=xlAscending, _ Header:=xlYes, _ OrderCustom:=1, _ MatchCase:=False -- HTH... Jim Thomlinson "Russ" wrote: I feel very foolish asking this question but I have been going round and round on this too long. I have the following code in a Userform (not in a module): Sheets(1).Activate Sheets(1).Range(Cells(3,1),Cells(15,20)).Select Selection.sort Key1:=Range(A2), Order1:=xlAscending _ , Key2:=Range(D2), Order2:=xlAscending _ , Header:=xlGuess, OrderCustom:=1, MatchCase:=False _ , Orientation:xlTopToBottom The code works fine. However, I now want to do the sort without activating sheet(1). I have tried all kinds of ways to do the ranges without using selection but to no avail. I went thru the postings and could not find another posting close to this. Can someone help me. -- russ |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
sorting on a non active sheet
Depending on the range you were sorting, you could have used:
..range("a2") or sameworksheet.range("a2") but (for me), it makes it easier to see that I'm sorting on the 2nd column of the range to sort. Russ wrote: Oh Dave you don't know how long I worked on this one. I can't thank you enough. As an aside - I do always use sheets("mysheet") but for illustration purposes i used sheets(1) in my sample code. Where I got all tangled up was trying to find the alternative for key1:=Range("A2") - i had not tried key1:=.columns(1). What would amateurs like me do without you guys. Thanks again. -- russ "Dave Peterson" wrote: with sheets(1) with .range(.cells(3,1),.cells(15,20)) .cells.sort Key1:=.columns(1), Order1:=xlAscending, _ Key2:=.columns(3), Order2:=xlAscending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:xlTopToBottom end with end with Notice all the dots (like .cells()). That means that that thing belongs to the object in the previous With statement. And I agree with Jim's tip about not letting xl guess (about headers). You know if you have them or not. Put that in your code (xlyes or xlno). And sheets(1) will be the left most sheet. I'd use the name: with sheets("mysheetnamehere") if I knew it. Russ wrote: I feel very foolish asking this question but I have been going round and round on this too long. I have the following code in a Userform (not in a module): Sheets(1).Activate Sheets(1).Range(Cells(3,1),Cells(15,20)).Select Selection.sort Key1:=Range(âœA2â), Order1:=xlAscending _ , Key2:=Range(âœD2â), Order2:=xlAscending _ , Header:=xlGuess, OrderCustom:=1, MatchCase:=False _ , Orientation:xlTopToBottom The code works fine. However, I now want to do the sort without activating sheet(1). I have tried all kinds of ways to do the ranges without using selection but to no avail. I went thru the postings and could not find another posting close to this. Can someone help me. -- russ -- Dave Peterson -- Dave Peterson |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
sorting on a non active sheet
I agree. The .columns(n) makes it easier. I think the dots not in the right
places was also giving me grief. I thought i had that finally figured out. Thanks again for your help. russ "Dave Peterson" wrote: Depending on the range you were sorting, you could have used: ..range("a2") or sameworksheet.range("a2") but (for me), it makes it easier to see that I'm sorting on the 2nd column of the range to sort. Russ wrote: Oh Dave you don't know how long I worked on this one. I can't thank you enough. As an aside - I do always use sheets("mysheet") but for illustration purposes i used sheets(1) in my sample code. Where I got all tangled up was trying to find the alternative for key1:=Range("A2") - i had not tried key1:=.columns(1). What would amateurs like me do without you guys. Thanks again. -- russ "Dave Peterson" wrote: with sheets(1) with .range(.cells(3,1),.cells(15,20)) .cells.sort Key1:=.columns(1), Order1:=xlAscending, _ Key2:=.columns(3), Order2:=xlAscending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:xlTopToBottom end with end with Notice all the dots (like .cells()). That means that that thing belongs to the object in the previous With statement. And I agree with Jim's tip about not letting xl guess (about headers). You know if you have them or not. Put that in your code (xlyes or xlno). And sheets(1) will be the left most sheet. I'd use the name: with sheets("mysheetnamehere") if I knew it. Russ wrote: I feel very foolish asking this question but I have been going round and round on this too long. I have the following code in a Userform (not in a module): Sheets(1).Activate Sheets(1).Range(Cells(3,1),Cells(15,20)).Select Selection.sort Key1:=Range(ââ¬ÅA2ââ¬Â), Order1:=xlAscending _ , Key2:=Range(ââ¬ÅD2ââ¬Â), Order2:=xlAscending _ , Header:=xlGuess, OrderCustom:=1, MatchCase:=False _ , Orientation:xlTopToBottom The code works fine. However, I now want to do the sort without activating sheet(1). I have tried all kinds of ways to do the ranges without using selection but to no avail. I went thru the postings and could not find another posting close to this. Can someone help me. -- russ -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Copy sheet and make new sheet active | Excel Discussion (Misc queries) | |||
I need to sort an active sheet using the col of the active cell | Excel Programming | |||
Active Cell Copy And Paste Sheet to Sheet | New Users to Excel | |||
Copy my active sheet to a new sheet and open with an input form | Excel Programming | |||
Copy from active sheet and paste into new sheet using info from cell in active | Excel Programming |