event after worksheet unprotect

S

sam

Here is sample code:

If Worksheets("Sheet1").Range("E5").Value = "1" Then
Worksheets("Sheet1").Protect
Else
If Worksheets("Sheet1").Range("E5").Value = "2" Then
Worksheets("Sheet1").Unprotect
Worksheets("Sheet1").Range("J8").Value = "111"
End If
End If

When I choose the value 2 in the dropdown list of range E5, it can
unprotect this worksheet. But, it doesn't execute the clause after
unprotect. However, after I click anything on this worksheet, the
clause after unprotect runs(111 appears on the range J8). I am confused
about this. Do you know how to fix this problem?Thank you!

Best Regards

Sam
 
G

Guest

I see no reason why what you have posted shouldn't work. The syntax could be
cleaned up a bit but it should not affect the actual execution... In your
title you mentioned "event". Is this code executed based on an event?

with Worksheets("Sheet1")
If .Range("E5").Value = "1" Then
.Protect
ElseIf .Range("E5").Value = "2" Then
.Unprotect
.Range("J8").Value = "111"
End If
end with
 
S

sam

It is one more event after unprotected that specific worksheet, like
enable some grayed option buttons.
obj.Object.Enabled = False
However, I need to click the worksheet again to make it happen. I don't
know why the code couldn't execute it directly.Do you have some idea
regarding this issue?

Regards

Sam
 

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

Similar Threads

Help with VB code 2
Problem copying name range 3
How to save the option button value 7
worksheet change macro 3
Excel 2013 Merge Data 2
Unprotect Workbook with Function 3
Simple Macro 1
Excel VBA 1

Top