ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Locking spreadsheet (https://www.excelbanter.com/excel-programming/295547-locking-spreadsheet.html)

ryan

Locking spreadsheet
 
I have written the following code but I continually get an error message

Sub Test()
Dim ws As Workshee
Set ws = ActiveShee
'Locking the Current Loan information section if Purchas

If Range("C9").Value = "Purchase" The
'Skip the Current Loan Information Sectio
ActiveSheet.Unprotec

ActiveSheet.Range("C15:C20,K15:K19").Locked = Tru

ActiveSheet.Protec
End If
End Su

When I try and run it, I get the error message; "Unable to set the locked property of the Range class".

I really am VERY new to this and have been trying to teach myself, but it is coming slowly. I am sure that I am making a simple mistake that someone will be able to fix.

Also, I want it set up so that it knows to run the second that "Purchase" is selected in the combobox associated with C9 (ComboBox6)

Thanks in advance

Rya


TH[_3_]

Locking spreadsheet
 
Excel VBA Help says you need to use UNION("C15:C20,K15:K19") to get what you
want. Range is only good specifying the upper left and lower right cell of a
contiguous range. I'd try that first (or separate your LOCKED command into
two lines).

Otherwise, if you have a password on that locked sheet, you'll have to
provide it with the .unprotect method (and with the .protect method too).
Like this:

ActiveSheet.Unprotect Password:="myPassword"

Or even

ActiveSheet.Unprotect Password:InputBox("Password to unprotect sheet?")

If there's no password, your code should be working.

TH

On 4/19/04 10:16, in article
, "Ryan"
wrote:

I have written the following code but I continually get an error message:
Sub Test()
Dim ws As Worksheet
Set ws = ActiveSheet
'Locking the Current Loan information section if Purchase

If Range("C9").Value = "Purchase" Then
'Skip the Current Loan Information Section
ActiveSheet.Unprotect

ActiveSheet.Range("C15:C20,K15:K19").Locked = True

ActiveSheet.Protect
End If
End Sub

When I try and run it, I get the error message; "Unable to set the locked
property of the Range class".

I really am VERY new to this and have been trying to teach myself, but it is
coming slowly. I am sure that I am making a simple mistake that someone will
be able to fix.

Also, I want it set up so that it knows to run the second that "Purchase" is
selected in the combobox associated with C9 (ComboBox6).

Thanks in advance.

Ryan




All times are GMT +1. The time now is 12:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com