LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default worksheet protection


"Todd" wrote in message
...
Is there a way to select all cells without a formula and
unlock them? Maybe a macro? I want to protect all the
cells with formulas and leave the rest open to changes.
Right now all cells with data are locked. I have a lot
of worksheets so doing this manually will take a LONG time.


TIA

Todd


Todd,
Open the VB editor for the workbook in question. Insert a module and
then paste the following code into the module. Then run it whenever you
need to. (May not be the most elegant way, but it worked for me). [BTW you
can also use edit, goto, special to select cells with formulas. Then right
click on the selection and make the changes. You would have to do it
separately for every sheet though]
Good luck!

Bob L.


Sub LockFormulas()
Dim mysheet As Worksheet
Dim myrange As Range
Dim mycell
For Each mysheet In ThisWorkbook.Worksheets

mysheet.Activate
Set myrange = mysheet.UsedRange

For Each mycell In myrange

Select Case mycell.Formula
Case Is = ""
mycell.Locked = False 'unlock empty cells

Case Else
'distinguish between constants and formulas
If Left(CStr(mycell.Formula), 1) = "=" Then
mycell.Locked = True
Else
mycell.Locked = False
End If

End Select
Next
mysheet.Protect 'Protect the sheet
Next
End Sub




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet Protection faeiz2 Excel Discussion (Misc queries) 3 January 6th 07 03:19 AM
Cell Protection vs. Worksheet Protection kmwhitt Excel Discussion (Misc queries) 4 September 24th 06 02:37 AM
Worksheet protection is gone and only wokbook protection can be se Eric C. Excel Discussion (Misc queries) 4 May 2nd 06 04:50 PM
worksheet protection Matt Excel Discussion (Misc queries) 1 March 3rd 06 09:20 PM
Worksheet Protection stwky New Users to Excel 2 April 12th 05 04:04 PM


All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"