Solved

Excel - Locking a Sheet

Posted on 2016-07-26
6
40 Views
Last Modified: 2016-07-26
I have a Excel workbook with multiple sheets.   Each sheet equals a month.

Many cells on a sheet are locked and some are unlocked and editable.

Each sheet has some cells pulling dynamic info from cells on a master sheet.

I'd like a button that at the end of the month i can click to lock the particular sheet from further editing including further changes in dynamic cells (lock the current dynamic values and stop changing based on the master sheet).    

Thanks for any input.
0
Comment
Question by:tailoreddigital
  • 4
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
Simulog earned 500 total points
ID: 41730248
Hi
Add a module, paste the following code into it and link a button on the worksheet to the macro
Option Explicit

Sub MakeStatic()
' This copies the used area and pastes values, turns on the locking of all used cells
' and locks the worksheet (without a password)
' Jörgen Möller 26Jul 2016
    With ActiveSheet.Range("A1", ActiveSheet.Range("A1").SpecialCells(xlCellTypeLastCell))
        .Copy
        .PasteSpecial Paste:=xlPasteValues
        .Locked = True
        .Range("A1").Select
    End With
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Open in new window


It should do the trick.

Good Luck
0
 
LVL 23

Author Comment

by:tailoreddigital
ID: 41730255
I'm testing this now.    

I know somebody is going to lock it and then realize that they need to change something.  

What code could i use to make it editable after MakeStatic?   It only would need to be editable, the dynamic cells don't need to revert to dynamic.
0
 
LVL 23

Author Comment

by:tailoreddigital
ID: 41730289
MakeStatic works.   I appreciate your expertise.    

To accomplish my need above, It looks like i'd just need to create another script that simply unprotects the active sheet.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 23

Author Closing Comment

by:tailoreddigital
ID: 41730314
Thanks for the help
0
 
LVL 2

Expert Comment

by:Simulog
ID: 41730315
Yes and that is simple
Option Explicit

Sub UnProtSheet()
    ActiveSheet.Unprotect
End Sub

Open in new window

0
 
LVL 23

Author Comment

by:tailoreddigital
ID: 41730358
Thanks again, have a great day
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This collection of functions covers all the normal rounding methods of just about any numeric value.
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now