Solved Sort 2 columns in a new created sheet

April 29, 2013 at 11:49:56
Specs: Windows 7
I'm trying to sort column s and column i on the newly created sheet NSheetName from a search result - how do I specify the sheet name in the following code and not to change my Sheet1

Range("s2").Select

Selection.Sort Key1:=Range("s2"), Order1:=xlDescending, Key2:=Range("i2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom

Thanks!


See More: Sort 2 columns in a new created sheet

Report •


#1
April 29, 2013 at 11:54:44
✔ Best Answer
Simba11,

I tried several variations of this without using a 'select' statement with no luck. Here is what I came up with that worked for me. Basically you had the right idea, but instead of selecting a range, I am selecting only the new sheet.

Sheets(NSheetName).Select
        Columns("A:S").Sort key1:=Range("S2"), order1:=xlDescending, _
        key2:=Range("I2"), order2:=xlAscending, Header:=xlYes

Law if Logical Argument: Anything is possible if you don't know what you're talking about.


Report •

#2
April 29, 2013 at 12:38:37
Thanks, Newbie10. It works great!!

Report •

#3
April 29, 2013 at 13:02:27
Glad I can help!!

Just so others know when reading this thread, 'NSheetName' is a variable and not the actual name of the sheet the op wants to select. Which is why:

Sheets(NSheetName).Select 

doesn't have the "" in the sheet name. If you know the name of the sheet and it will never change you can use:

Sheets("Sheet1").Select 

which will select the sheet named 'Sheet1'.

Law if Logical Argument: Anything is possible if you don't know what you're talking about.


Report •
Related Solutions


Ask Question