Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default What am I doing wrong?

The code below works great if the active worksheet is Employee_List, but
if I call it from another active worksheet, I get a Sort referance not
valid. This is supoose to sort the data on the Employee_List worksheet,
while leaving me on the current (active worksheet)


Private Sub CommandButton1_Click()

'Sort by Paratransit Drivers First Name

Worksheets("Employee_List").Range("AA1").Value = 1

Dim wks As Worksheet
Set wks = Worksheets("Employee_List")
With wks.Range("A1:Z300")
..Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Key3:=Range("A2"), Order3:=xlAscending,
Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=
_
xlSortNormal
End With

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default What am I doing wrong?

Why not early in your existing code After the Dim Line, enter:
TempSheetName = Activesheet.name

then after the line

End with
enter:
Worksheets(TempSheetName).Activate

Would that work for you?




"Patrick Simonds" wrote in message
...
The code below works great if the active worksheet is Employee_List, but if
I call it from another active worksheet, I get a Sort referance not valid.
This is supoose to sort the data on the Employee_List worksheet, while leaving
me on the current (active worksheet)


Private Sub CommandButton1_Click()

'Sort by Paratransit Drivers First Name

Worksheets("Employee_List").Range("AA1").Value = 1

Dim wks As Worksheet
Set wks = Worksheets("Employee_List")
With wks.Range("A1:Z300")
.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Key3:=Range("A2"), Order3:=xlAscending, Header:=
_
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
End With

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default What am I doing wrong?

Hi Alan,
It worked for me after I added "wks." before each of the three sort
keys:

Key1:=Range("B2") becomes Key1:= wks.Range("B2")
Key2:=Range("C2") becomes Key2:=wks.Range("C2")
Key3:=Range("A2") becomes Key3:=wks.Range("A2")

Ken Johnson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default What am I doing wrong?

Hi Patrick,
I don't know where I got the Name "Alan" from!

Ken Johnson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default What am I doing wrong?

Thank you for the quick fix.

"Ken Johnson" wrote in message
ups.com...
Hi Alan,
It worked for me after I added "wks." before each of the three sort
keys:

Key1:=Range("B2") becomes Key1:= wks.Range("B2")
Key2:=Range("C2") becomes Key2:=wks.Range("C2")
Key3:=Range("A2") becomes Key3:=wks.Range("A2")

Ken Johnson





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default What am I doing wrong?

Hi Patrick,
You're welcome, glad I could help.
Thanks for the feedback.
Ken Johnson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default What am I doing wrong?

patrick, that's what i had posted in your original post a few days ago:

..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


--


Gary


"Patrick Simonds" wrote in message
...
The code below works great if the active worksheet is Employee_List,
but if I call it from another active worksheet, I get a Sort referance not
valid. This is supoose to sort the data on the Employee_List worksheet,
while leaving me on the current (active worksheet)


Private Sub CommandButton1_Click()

'Sort by Paratransit Drivers First Name

Worksheets("Employee_List").Range("AA1").Value = 1

Dim wks As Worksheet
Set wks = Worksheets("Employee_List")
With wks.Range("A1:Z300")
.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Key3:=Range("A2"), Order3:=xlAscending,
Header:= _
xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=
_
xlSortNormal
End With

End Sub



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
help please what am i doing wrong? Nevyn Excel Discussion (Misc queries) 1 February 9th 10 10:50 PM
Insert Calculated Field (wrong Qty*Price = wrong Amount) Edmund Excel Discussion (Misc queries) 8 October 4th 07 12:13 PM
Where am I going wrong? Pank Excel Discussion (Misc queries) 2 July 13th 05 01:05 PM
Please Tell Me What I Am Doing Wrong kidd Excel Programming 0 October 30th 04 01:30 AM
What is wrong?? willroy[_2_] Excel Programming 1 December 12th 03 01:33 PM


All times are GMT +1. The time now is 10:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"