Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Trouble with Sheet Deactivate macro

Hi All......

I am trying to set up Worksheet Deactivate macro to
1-unprotect the sheet
2-clear contents of a specific range
3-hide the sheet

My present code:
Private Sub Worksheet_Deactivate()
ActiveSheet.Unprotect
Range("FieldCelleratorsX2").ClearContents
ActiveSheet.Visible = False
End Sub

It's unpredictable, sometimes it hides the sheet I'm GOING to, sometimes it
won't UNPROTECT.......the only part that seems to work consistantly is the
"clearcontents" line..........what an I doing wrong please?

TIA
Vaya con Dios,
Chuck, CABGx3


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Trouble with Sheet Deactivate macro

Hi Chuck,

I think the problem is caused because in the deactoivate event the
activesheet is the sheet gone to, not from.

You could use the worksbook sheetdeactivate event, as that passes the exited
sh as an argument. So just test it's name

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
If Sh.Name = "Chuck" Then
Sh.Unprotect
Sh.Range("FieldCelleratorsX2").ClearContents
Sh.Visible = False
End If
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"CLR" wrote in message
...
Hi All......

I am trying to set up Worksheet Deactivate macro to
1-unprotect the sheet
2-clear contents of a specific range
3-hide the sheet

My present code:
Private Sub Worksheet_Deactivate()
ActiveSheet.Unprotect
Range("FieldCelleratorsX2").ClearContents
ActiveSheet.Visible = False
End Sub

It's unpredictable, sometimes it hides the sheet I'm GOING to, sometimes

it
won't UNPROTECT.......the only part that seems to work consistantly is the
"clearcontents" line..........what an I doing wrong please?

TIA
Vaya con Dios,
Chuck, CABGx3




  #3   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Trouble with Sheet Deactivate macro

Thanks Bob.......

Do I simply replace my present macro behind the Sheet with this one, or do I
put it behind the Workbook.......I have 36 sheets I want to do this to and
was thinking I needed a macro behind each sheet......

Vaya con Dios,
Chuck, CABGx3

"Bob Phillips" wrote:

Hi Chuck,

I think the problem is caused because in the deactoivate event the
activesheet is the sheet gone to, not from.

You could use the worksbook sheetdeactivate event, as that passes the exited
sh as an argument. So just test it's name

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
If Sh.Name = "Chuck" Then
Sh.Unprotect
Sh.Range("FieldCelleratorsX2").ClearContents
Sh.Visible = False
End If
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"CLR" wrote in message
...
Hi All......

I am trying to set up Worksheet Deactivate macro to
1-unprotect the sheet
2-clear contents of a specific range
3-hide the sheet

My present code:
Private Sub Worksheet_Deactivate()
ActiveSheet.Unprotect
Range("FieldCelleratorsX2").ClearContents
ActiveSheet.Visible = False
End Sub

It's unpredictable, sometimes it hides the sheet I'm GOING to, sometimes

it
won't UNPROTECT.......the only part that seems to work consistantly is the
"clearcontents" line..........what an I doing wrong please?

TIA
Vaya con Dios,
Chuck, CABGx3





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Trouble with Sheet Deactivate macro

No, remove your current code, and just put in in ThisWorkbook, and it is
workbook scope. You just check sh.name if it is to apply to any specific
sheets.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"CLR" wrote in message
...
Thanks Bob.......

Do I simply replace my present macro behind the Sheet with this one, or do

I
put it behind the Workbook.......I have 36 sheets I want to do this to and
was thinking I needed a macro behind each sheet......

Vaya con Dios,
Chuck, CABGx3

"Bob Phillips" wrote:

Hi Chuck,

I think the problem is caused because in the deactoivate event the
activesheet is the sheet gone to, not from.

You could use the worksbook sheetdeactivate event, as that passes the

exited
sh as an argument. So just test it's name

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
If Sh.Name = "Chuck" Then
Sh.Unprotect
Sh.Range("FieldCelleratorsX2").ClearContents
Sh.Visible = False
End If
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"CLR" wrote in message
...
Hi All......

I am trying to set up Worksheet Deactivate macro to
1-unprotect the sheet
2-clear contents of a specific range
3-hide the sheet

My present code:
Private Sub Worksheet_Deactivate()
ActiveSheet.Unprotect
Range("FieldCelleratorsX2").ClearContents
ActiveSheet.Visible = False
End Sub

It's unpredictable, sometimes it hides the sheet I'm GOING to,

sometimes
it
won't UNPROTECT.......the only part that seems to work consistantly is

the
"clearcontents" line..........what an I doing wrong please?

TIA
Vaya con Dios,
Chuck, CABGx3







  #5   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 1,998
Default Trouble with Sheet Deactivate macro

Okey doke.........thank you muchly

Vaya con Dios,
Chuck, CABGx3



"Bob Phillips" wrote:

No, remove your current code, and just put in in ThisWorkbook, and it is
workbook scope. You just check sh.name if it is to apply to any specific
sheets.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"CLR" wrote in message
...
Thanks Bob.......

Do I simply replace my present macro behind the Sheet with this one, or do

I
put it behind the Workbook.......I have 36 sheets I want to do this to and
was thinking I needed a macro behind each sheet......

Vaya con Dios,
Chuck, CABGx3

"Bob Phillips" wrote:

Hi Chuck,

I think the problem is caused because in the deactoivate event the
activesheet is the sheet gone to, not from.

You could use the worksbook sheetdeactivate event, as that passes the

exited
sh as an argument. So just test it's name

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
If Sh.Name = "Chuck" Then
Sh.Unprotect
Sh.Range("FieldCelleratorsX2").ClearContents
Sh.Visible = False
End If
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"CLR" wrote in message
...
Hi All......

I am trying to set up Worksheet Deactivate macro to
1-unprotect the sheet
2-clear contents of a specific range
3-hide the sheet

My present code:
Private Sub Worksheet_Deactivate()
ActiveSheet.Unprotect
Range("FieldCelleratorsX2").ClearContents
ActiveSheet.Visible = False
End Sub

It's unpredictable, sometimes it hides the sheet I'm GOING to,

sometimes
it
won't UNPROTECT.......the only part that seems to work consistantly is

the
"clearcontents" line..........what an I doing wrong please?

TIA
Vaya con Dios,
Chuck, CABGx3








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 a macro when used and reactivate again Ber Excel Discussion (Misc queries) 1 April 23rd 10 04:35 PM
Deactivate sheet Jay Northrop Excel Programming 5 July 22nd 05 03:13 PM
How to deactivate cells without macro references Adomas Excel Programming 1 June 14th 05 11:14 PM
activate/deactivate button with macro at given condition arcq Excel Programming 1 March 17th 05 05:35 AM
Sort sheet on sheet's Deactivate event BountyHunter Excel Programming 3 May 25th 04 08:31 AM


All times are GMT +1. The time now is 12:54 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"