OzGrid

How to protect cells

< Back to Search results

 Category: [Excel]  Demo Available 

How to protect cells

 

Requirement:

 

The user has a sheet that is "Protected", with certain cells Unprotected to allow for user input.
How can the user use VBA to change this to have the sheet protected in its entirely (all cells protected)?

Or at least provide a popup message if an unprotected cell is selected.

 

https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/149336-completely-lock-a-partially-locked-sheet

 

Solution:

 

Code:
Sub x()

With ActiveSheet
    .Unprotect
    .Cells.Locked = True
    .Protect
End With

End Sub

 

Obtained from the OzGrid Help Forum.

Solution provided by Stephen R.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to use a macro or formula to copy data from cell to all cells in that group in adjacent column
How to copy specific cells based on a criteria from one sheet to a different sheet
How to open hyperlinks in multiple cells
How to set all non zero column cells to column header

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)