Solved

Excel - Locking a Sheet

Posted on 2016-07-26
6
69 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 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
Technology Partners: 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
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…

707 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