How to protect ALL formulas in a WORKBOOK

G

Guest

Is there an easy way to protect all formulas in an entire workbook at once?
I have a workbook with over 100 sheets and would like to protect all the
formulas on each sheet without having to protect each sheet individually.
 
P

Paul B

liebzeit, here is one way,

Sub Lock_All_Formulas()
'will lock & hide all cells with formulas in them
'and also unlock all cells without formulas in them
'and protect the sheet

Dim cell As Range
Dim sht As Worksheet
Application.ScreenUpdating = False
For Each sht In Worksheets
sht.Activate
For Each cell In sht.UsedRange
If cell.HasFormula = True Then
cell.Locked = True
cell.FormulaHidden = True
Else: cell.Locked = False
End If
Next cell
sht.Protect Password:="123" 'Change password here
Next sht
Application.ScreenUpdating = True
End Sub

To put in this macro, from your workbook right-click the workbook's icon and
pick View Code. This icon is to the left of the "File" menu this will open
the VBA editor, in Project Explorer click on your workbook name, if you
don't see it press CTRL + r to open the Project Explorer, then go to insert,
module, and paste the code in the window that opens on the right hand side,
press Alt and Q to close this window and go back to your workbook and press
alt and F8, this will bring up a box to pick the Macro from, click on the
Macro name to run it. If you are using excel 2000 or newer you may have to
change the macro security settings to get the macro to run. To change the
security settings go to tools, macro, security, security level and set it to
medium


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003
 
J

JE McGimpsey

one way:

Public Sub HideAllFormulae()
Const sPWORD As String = "drowssap"
Dim ws As Worksheet
On Error Resume Next
For Each ws In Worksheets
With ws
.Unprotect sPWORD
With .Cells.SpecialCells(xlCellTypeFormulas)
.Locked = True
.FormulaHidden = True
End With
With .Cells.SpecialCells(xlCellTypeConstants)
.Locked = False
.FormulaHidden = False
End With
.Protect sPWORD
End With
Next ws
On Error GoTo 0
End Sub
 
G

Guest

Thank you for your reply. I was hoping for a simple solution without using
macros. I prefer not to use macros since I will be distributing this
workbook to a number of users who will simply be using it to enter data (on
their home computers.) Most are novice computer users, so the complexity of
using macros (changing settings, etc.) would be too much to ask of them.
 
K

Ken Wright

Then you are limited to doing it sheet by sheet manually.

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 97/00/02/03

------------------------------­------------------------------­----------------
It's easier to beg forgiveness than ask permission :)
------------------------------­------------------------------­----------------
 
E

EdMac

Use ASAP utilities available from asap-utilities.com

It is free and has this as a facility

E
 
E

e.marans

Great Macro. I installed it and it works fine, just one question. How
do you reverse it. I copied the macro to an new one and change the
first two True's to false, this unhide the formulas but the sheets were
still not keen to the idea that the data be changed.
Thanks
Erle
 
J

JE McGimpsey

Great Macro. I installed it and it works fine, just one question. How
do you reverse it. I copied the macro to an new one and change the
first two True's to false, this unhide the formulas but the sheets were
still not keen to the idea that the data be changed.

Unprotect the worksheet (Tools/Protection/Unprotect Sheet). The password
in the macro is "drowssap"
 
E

e.marans

Hi and thanks again. Is there anyway to add into a macro so that I can
inpliment it on mutipule Workshees in a Workbook.

Thanks
Erle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top