Problem with Worksheet_Activate event

R

Raj

A workbook as two sheets: Master and Details. The requirement is that
the data entry in the Details worksheet is not to be allowed unless
the Master worksheet is protected. To achieve this the following code
was written in the Worksheet_activate event of the Details sheet.

Private Sub Worksheet_Activate()

If Worksheets("Master").ProtectContents <> True Then MsgBox "Please
protect 'Master' sheet": Worksheets("Master").Activate
End Sub

When the Details sheet is activated without the Master sheet being
protected, there is an endless loop. How do I resolve the issue?

Any other ideas to achieve this would also be welcome.

Thanks in advance for all the help.

Regards,
Raj
 
J

john

instead of doing a test and reporting to user why not just protect the
required sheet when Details sheet is activated?

Private Sub Worksheet_Activate()
Worksheets("Master").Protect Contents:=True
End Sub
 
B

Bob Phillips

That doesn't loop for me. Is there code in Master as well?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
R

Raj

The requirement is like this. The user has to select values in two
cells and click on a worksheet commandbutton to lock the cells.
Clicking on the button will lock the cells and protect the sheet. In
case the user has not done that, he should not be allowed to do data
entry in the Details sheet. The code is prevent the user from doing
data entry in the Details sheet unless he locks the cells and protects
the master sheet.

The Master sheet has code in it (for the button) as well as some other
code.

Regards,
Raj
 

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