ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sort Method question (https://www.excelbanter.com/excel-programming/303040-sort-method-question.html)

CG Rosén

Sort Method question
 
Good Day Group,

Below code works fine as long Sheet(3) is active. How to
write the code to work also when another WorkSheet is
the active sheet.? Is that possible?

Brgds

CG Rosén

Sheets(3).Columns("O:U").Sort Key1:=Range("O1"), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers



keepITcool

Sort Method question
 
like this it should work..

Since you do not define the parent of sheets(3)
if will run on the ACTIVEworkbook.


WITH Sheets(3).Columns("O:U")
.Sort Key1:= .Cells(1), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
END WITH


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"CG Rosén" wrote:

Good Day Group,

Below code works fine as long Sheet(3) is active. How to
write the code to work also when another WorkSheet is
the active sheet.? Is that possible?

Brgds

CG Rosén





Nigel

Sort Method question
 

Try......

ActiveSheet.Columns("O:U").Sort Key1:=Range("O1"), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers

Cheers
Nigel

"CG Rosén" wrote in message
...
Good Day Group,

Below code works fine as long Sheet(3) is active. How to
write the code to work also when another WorkSheet is
the active sheet.? Is that possible?

Brgds

CG Rosén

Sheets(3).Columns("O:U").Sort Key1:=Range("O1"), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers






All times are GMT +1. The time now is 10:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com