Before Worksheet Close

J

jswalsh33

Is there a way to run a particular macro when focus is change from a
particular worksheet to any other worksheet by selecting another worksheet?

Thanks for your help.

Jim Walsh
 
B

Bob Phillips

Private Sub Worksheet_Deactivate()
....your code
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.
 
J

Jacob Skaria

DeActivate event is triggered when you select another worksheet..

Private Sub Worksheet_Deactivate()
MsgBox "ok"
End Sub

If this post helps click Yes
 
D

Dave Peterson

If the two worksheets are in separate workbooks, you may want to use the
workbook event:
Private Sub Workbook_Deactivate()

(maybe both????)
 
J

jswalsh33

Bob,

That works good, but it allows the newly selected worksheet to be activated
before the the Deactivate code operates. I tried putting in
"Application.ScreenUpdating = False" as the first line of code but that did
not prevent it. Is there a way to keep the screen from switching to the newly
selected worksheets?

Thanks Again,

Jim Walsh
 
B

Bob Phillips

I can't see it because that sheet is not deactivated until something else is
activated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top