View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
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