Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Deactivate sheet

Hello!

I'm having trouble with Deactivate Sheet. My workbook has two sheets, Sheet1
and Sheet2. In Sheet1, I have this macro:

Private Sub Worksheet_Deactivate()
Worksheets("Sheet1").Activate
Range("A1:A10").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
End Sub

However, when I click on Sheet2, Sheet1 won't "let go." I suppose it's
because of the third line [Range("A1:A10").Select]. but, without that line,
I get an error message. How do I get the macro to "let go" of sheet 1 and go
to sheet 2 when I click on Sheet2?

Also, I tested another similar Worksheet_Deactivate macro (not using a sort
routine) which worked okay, but it left a selection "shadow" on Sheet2.

Your help is appreciated.

Thanks,

Jay


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Deactivate sheet

Jay,
'-------------------
Private Sub Worksheet_Deactivate() 'Sheet1
With Worksheets("Sheet1")
.Range("A1:A10").Sort Key1:=.Range("A1"), _
Order1:=xlAscending
End With
End Sub
'-------------------
Regards,
Jim Cone
San Francisco, USA


"Jay Northrop" wrote in
message news:HoZDe.46061$4o.26539@fed1read06...
Hello!
I'm having trouble with Deactivate Sheet. My workbook has two sheets, Sheet1
and Sheet2. In Sheet1, I have this macro:

Private Sub Worksheet_Deactivate()
Worksheets("Sheet1").Activate
Range("A1:A10").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
End Sub

However, when I click on Sheet2, Sheet1 won't "let go." I suppose it's
because of the third line [Range("A1:A10").Select]. but, without that line,
I get an error message. How do I get the macro to "let go" of sheet 1 and go
to sheet 2 when I click on Sheet2?
Also, I tested another similar Worksheet_Deactivate macro (not using a sort
routine) which worked okay, but it left a selection "shadow" on Sheet2.
Your help is appreciated.
Thanks,
Jay


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Deactivate sheet

Private Sub Worksheet_Deactivate()
Me.Range("A1:A10").Sort Key1:=Range("A1"), Order1:=xlAscending
End Sub

Regards
Rowan

"Jay Northrop" wrote:

Hello!

I'm having trouble with Deactivate Sheet. My workbook has two sheets, Sheet1
and Sheet2. In Sheet1, I have this macro:

Private Sub Worksheet_Deactivate()
Worksheets("Sheet1").Activate
Range("A1:A10").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
End Sub

However, when I click on Sheet2, Sheet1 won't "let go." I suppose it's
because of the third line [Range("A1:A10").Select]. but, without that line,
I get an error message. How do I get the macro to "let go" of sheet 1 and go
to sheet 2 when I click on Sheet2?

Also, I tested another similar Worksheet_Deactivate macro (not using a sort
routine) which worked okay, but it left a selection "shadow" on Sheet2.

Your help is appreciated.

Thanks,

Jay



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Deactivate sheet

I see Jim gives the same answer as me...

Private Sub Worksheet_Deactivate()
With Worksheets("Sheet1").Range("A1:A10")
.Sort Key1:=Range("A1"), Order1:=xlAscending
End With
End Sub

The key here is to remember that cells or ranges don't have to be active or
selected .... they don't even have to be on an active sheet, to be
manipulated in most ways.



"Jay Northrop" wrote:

Hello!

I'm having trouble with Deactivate Sheet. My workbook has two sheets, Sheet1
and Sheet2. In Sheet1, I have this macro:

Private Sub Worksheet_Deactivate()
Worksheets("Sheet1").Activate
Range("A1:A10").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
End Sub

However, when I click on Sheet2, Sheet1 won't "let go." I suppose it's
because of the third line [Range("A1:A10").Select]. but, without that line,
I get an error message. How do I get the macro to "let go" of sheet 1 and go
to sheet 2 when I click on Sheet2?

Also, I tested another similar Worksheet_Deactivate macro (not using a sort
routine) which worked okay, but it left a selection "shadow" on Sheet2.

Your help is appreciated.

Thanks,

Jay



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Deactivate sheet

Thanks, Jim! This works and I appreciate your help on this.

Jay


"Jim Cone" wrote in message
...
Jay,
'-------------------
Private Sub Worksheet_Deactivate() 'Sheet1
With Worksheets("Sheet1")
.Range("A1:A10").Sort Key1:=.Range("A1"), _
Order1:=xlAscending
End With
End Sub
'-------------------
Regards,
Jim Cone
San Francisco, USA


"Jay Northrop" wrote in
message news:HoZDe.46061$4o.26539@fed1read06...
Hello!
I'm having trouble with Deactivate Sheet. My workbook has two sheets,
Sheet1
and Sheet2. In Sheet1, I have this macro:

Private Sub Worksheet_Deactivate()
Worksheets("Sheet1").Activate
Range("A1:A10").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
End Sub

However, when I click on Sheet2, Sheet1 won't "let go." I suppose it's
because of the third line [Range("A1:A10").Select]. but, without that
line,
I get an error message. How do I get the macro to "let go" of sheet 1 and
go
to sheet 2 when I click on Sheet2?
Also, I tested another similar Worksheet_Deactivate macro (not using a
sort
routine) which worked okay, but it left a selection "shadow" on Sheet2.
Your help is appreciated.
Thanks,
Jay






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Deactivate sheet

I like using the Me keyword, too. But I'd add it to the the key, too.

Private Sub Worksheet_Deactivate()
Me.Range("A1:A10").Sort Key1:=me.Range("A1"), Order1:=xlAscending
End Sub

Rowan wrote:

Private Sub Worksheet_Deactivate()
Me.Range("A1:A10").Sort Key1:=Range("A1"), Order1:=xlAscending
End Sub

Regards
Rowan

"Jay Northrop" wrote:

Hello!

I'm having trouble with Deactivate Sheet. My workbook has two sheets, Sheet1
and Sheet2. In Sheet1, I have this macro:

Private Sub Worksheet_Deactivate()
Worksheets("Sheet1").Activate
Range("A1:A10").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
End Sub

However, when I click on Sheet2, Sheet1 won't "let go." I suppose it's
because of the third line [Range("A1:A10").Select]. but, without that line,
I get an error message. How do I get the macro to "let go" of sheet 1 and go
to sheet 2 when I click on Sheet2?

Also, I tested another similar Worksheet_Deactivate macro (not using a sort
routine) which worked okay, but it left a selection "shadow" on Sheet2.

Your help is appreciated.

Thanks,

Jay




--

Dave Peterson
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
Deactivate worksheet Cordobes Excel Discussion (Misc queries) 3 December 4th 05 10:16 AM
Deactivate a cell Paul Excel Programming 1 March 14th 05 10:44 PM
deactivate fullscreen MD Excel Programming 3 March 13th 05 08:52 PM
Sort sheet on sheet's Deactivate event BountyHunter Excel Programming 3 May 25th 04 08:31 AM
Deactivate Formula DME Excel Programming 2 February 11th 04 09:00 PM


All times are GMT +1. The time now is 04:38 PM.

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

About Us

"It's about Microsoft Excel"