Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel - Locking a Sheet

Posted on 2016-07-26
6
Medium Priority
?
78 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
Simulog earned 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

597 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