Protecting Sheet From VBA is Locking Cells!!!

joes2007

New Member
Joined
Jan 10, 2018
Messages
18
I have an application that I made in Excel. I have 2 subs in a module, one to un-protect the active sheet, another to protect.

One of my pages has some cells unlocked. When I call the two subs to protect/un-protect, everything works just fine. In another sheet however... everytime I call one of the two subs, it seems to RE-lock the cells I have set as 'UNLOCKED'.

Subs in module:

Code:
Sub unlocksheet()
'call unlocksheet from any page of code to unprotect activesheet
    ActiveSheet.Unprotect Password:="tfi1355"
    
End Sub


Sub locksheet()
'call locksheet from any page of code to protect activesheet
    ActiveSheet.Protect Password:="tfi1355"
    
End Sub

Code that seems to be causing the issue:

Code:
Private Sub sh05clear_Click()


    Call pre_select_view 'contains its own unlock/lock
    Call select_view 'contains its own unlock/lock
    
 Call unlocksheet
 
    'clears existing input
    Range("o7").Clear
    
    'clears work order input
    Range("o21").Clear
    
    'clears brady input
    Range("o35").Clear
    
    'clears quantity input
    Range("n47").Clear
       
    'defines selection range as unselected
    Range("n50").Value = "unselected"
    
    'clears lot input
    Range("n53").Clear
    
    'clears processed range
    Range("r47").Value = ""
    
    'clears the tables for brady scans and 2d scans
    Range("o10:x10").ClearContents
    Range("o38:x38").ClearContents
    
    'sets workoder date selection to todays date
    Range("q25").Value = today
    
    
    
Call locksheet
    


End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
If cell S8 is unlocked and I run the below line it is still unlocked
Code:
Range("S8").ClearContents

If cell S7 is unlocked and then it becomes locked after the code runs
Code:
Range("S7").Clear
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,834
Members
449,192
Latest member
mcgeeaudrey

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top