ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sort Question (https://www.excelbanter.com/excel-programming/348595-sort-question.html)

Patrick Simonds

Sort Question
 
I want to use the following code to sort a worksheet (Employee_List), but I
do not want the sorted worksheet to be active:

Range("A3:D300").Select

Selection.Sort Key1:=Range("D4"), Order1:=xlAscending, Key2:=Range("A4")
_
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select



Gary Keramidas

Sort Question
 
this doesn't have to have the sheet active

Option Explicit
Sub sort()
Dim wks As Worksheet
Set wks = Worksheets("sheet1")
With wks.Range("A3:D300")
..sort Key1:=wks.Range("D4"), Order1:=xlAscending, Key2:=wks.Range("A4"), _
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select
End With
End Sub

--


Gary


"Patrick Simonds" wrote in message
...
I want to use the following code to sort a worksheet (Employee_List), but I
do not want the sorted worksheet to be active:

Range("A3:D300").Select

Selection.Sort Key1:=Range("D4"), Order1:=xlAscending,
Key2:=Range("A4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select




Patrick Simonds

Sort Question
 
OK this is exactly what I put in, but it did not do anything:

Option Explicit
Sub sort()
Dim wks As Worksheet
Set wks = Worksheets("Employee_List")
With wks.Range("A3:D300")
..sort Key1:=wks.Range("D4"), Order1:=xlAscending, Key2:=wks.Range("A4"), _
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select
End With

End Sub


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this doesn't have to have the sheet active

Option Explicit
Sub sort()
Dim wks As Worksheet
Set wks = Worksheets("sheet1")
With wks.Range("A3:D300")
.sort Key1:=wks.Range("D4"), Order1:=xlAscending, Key2:=wks.Range("A4"), _
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select
End With
End Sub

--


Gary


"Patrick Simonds" wrote in message
...
I want to use the following code to sort a worksheet (Employee_List), but
I do not want the sorted worksheet to be active:

Range("A3:D300").Select

Selection.Sort Key1:=Range("D4"), Order1:=xlAscending,
Key2:=Range("A4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select






Patrick Simonds

Sort Question
 
Got it to work, At the end of the .sort line it should have been B4 not A4.
Thanks for your help.


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this doesn't have to have the sheet active

Option Explicit
Sub sort()
Dim wks As Worksheet
Set wks = Worksheets("sheet1")
With wks.Range("A3:D300")
.sort Key1:=wks.Range("D4"), Order1:=xlAscending, Key2:=wks.Range("A4"), _
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select
End With
End Sub

--


Gary


"Patrick Simonds" wrote in message
...
I want to use the following code to sort a worksheet (Employee_List), but
I do not want the sorted worksheet to be active:

Range("A3:D300").Select

Selection.Sort Key1:=Range("D4"), Order1:=xlAscending,
Key2:=Range("A4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select






Gary Keramidas

Sort Question
 
if sheet 2 is the active sheet and run this, it sorts the employee_list
sheet test data i have. are you sure the sort keys are correct?

--


Gary


"Patrick Simonds" wrote in message
...
OK this is exactly what I put in, but it did not do anything:

Option Explicit
Sub sort()
Dim wks As Worksheet
Set wks = Worksheets("Employee_List")
With wks.Range("A3:D300")
.sort Key1:=wks.Range("D4"), Order1:=xlAscending, Key2:=wks.Range("A4"), _
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select
End With

End Sub


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this doesn't have to have the sheet active

Option Explicit
Sub sort()
Dim wks As Worksheet
Set wks = Worksheets("sheet1")
With wks.Range("A3:D300")
.sort Key1:=wks.Range("D4"), Order1:=xlAscending, Key2:=wks.Range("A4"),
_
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select
End With
End Sub

--


Gary


"Patrick Simonds" wrote in message
...
I want to use the following code to sort a worksheet (Employee_List), but
I do not want the sorted worksheet to be active:

Range("A3:D300").Select

Selection.Sort Key1:=Range("D4"), Order1:=xlAscending,
Key2:=Range("A4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select








Gary Keramidas

Sort Question
 
you're welcome, glad you got it working

--


Gary


"Patrick Simonds" wrote in message
...
Got it to work, At the end of the .sort line it should have been B4 not
A4. Thanks for your help.


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this doesn't have to have the sheet active

Option Explicit
Sub sort()
Dim wks As Worksheet
Set wks = Worksheets("sheet1")
With wks.Range("A3:D300")
.sort Key1:=wks.Range("D4"), Order1:=xlAscending, Key2:=wks.Range("A4"),
_
Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select
End With
End Sub

--


Gary


"Patrick Simonds" wrote in message
...
I want to use the following code to sort a worksheet (Employee_List), but
I do not want the sorted worksheet to be active:

Range("A3:D300").Select

Selection.Sort Key1:=Range("D4"), Order1:=xlAscending,
Key2:=Range("A4") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=2,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
Range("A3").Select









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

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