Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default worksheet protection

I tried the macro and I am getting the same error
message "unable to set locked property of the range class"?

Is there an option or preference or something I selected
to make this happen? Two macros giving the same error, I
must be doing something wrong.


Todd.

-----Original Message-----

"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




.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default worksheet protection


"Todd" wrote in message
...
I tried the macro and I am getting the same error
message "unable to set locked property of the range class"?

Is there an option or preference or something I selected
to make this happen? Two macros giving the same error, I
must be doing something wrong.


Todd.

-----Original Message-----

"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




.


Todd,
Your problem is that the sheets are protected so cannot be locked. I
added a line of code to unprotect the sheets first, and then protect them
after doing the locks.

Here it is:
Sub LockFormulas()
Dim mysheet As Worksheet
Dim myrange As Range
Dim mycell
For Each mysheet In ThisWorkbook.Worksheets
mysheet.Unprotect
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
Let me know if that takes care of it.

Bob L.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default worksheet protection

Hi Bob,

Thanks for the help. Its still not working. It does run
though. Its not getting error messages like before.
The macro runs but does not unlock any cells. I ran it on
sheets that were both protected and unprotected and I made
a sheet from scratch with both simple equations and text
only cells. I can't get it to work.

Thanks again,


Todd.


-----Original Message-----

"Todd" wrote in message
...
I tried the macro and I am getting the same error
message "unable to set locked property of the range

class"?

Is there an option or preference or something I selected
to make this happen? Two macros giving the same error,

I
must be doing something wrong.


Todd.

-----Original Message-----

"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




.


Todd,
Your problem is that the sheets are protected so

cannot be locked. I
added a line of code to unprotect the sheets first, and

then protect them
after doing the locks.

Here it is:
Sub LockFormulas()
Dim mysheet As Worksheet
Dim myrange As Range
Dim mycell
For Each mysheet In ThisWorkbook.Worksheets
mysheet.Unprotect
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
Let me know if that takes care of it.

Bob L.


.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default worksheet protection


"Todd" wrote in message
...
Hi Bob,

Thanks for the help. Its still not working. It does run
though. Its not getting error messages like before.
The macro runs but does not unlock any cells. I ran it on
sheets that were both protected and unprotected and I made
a sheet from scratch with both simple equations and text
only cells. I can't get it to work.

Thanks again,


Todd.


-----Original Message-----

"Todd" wrote in message
...
I tried the macro and I am getting the same error
message "unable to set locked property of the range

class"?

Is there an option or preference or something I selected
to make this happen? Two macros giving the same error,

I
must be doing something wrong.


Todd.

-----Original Message-----

"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




.


Todd,
Your problem is that the sheets are protected so

cannot be locked. I
added a line of code to unprotect the sheets first, and

then protect them
after doing the locks.

Here it is:
Sub LockFormulas()
Dim mysheet As Worksheet
Dim myrange As Range
Dim mycell
For Each mysheet In ThisWorkbook.Worksheets
mysheet.Unprotect
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
Let me know if that takes care of it.

Bob L.


.

Todd,
The code needs to be in the same workbook as the sheets you want to
operate upon. Assuming you have that right, I don't know what the problem
could be. I did it in Excel 2000. I will email you the file, assuming the
post address is okay as is.

Bob L.


Reply
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 06:11 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"