Computing.Net > Forums > Office Software > Cell Protection

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Cell Protection

Reply to Message Icon

Name: hrajan
Date: July 12, 2006 at 13:38:57 Pacific
OS: Windows XP
CPU/Ram: P4, 2GB RAM
Product: IBM ThinkCenter
Comment:

I have the following piece of code in VB.

ActiveSheet.Unprotect

ActiveSheet.Range("C3:C120").Locked = False
ActiveSheet.Range("C10:C13").Interior.Color = RGB(211, 211, 211)
ActiveSheet.Range("C10:C13").Value = 0
ActiveSheet.Range("C10:C13").Locked = True

The sub is executed from a Change event. What the routine does is to unprotect a sheet, change the values of a few cells to 0, change their background and then protect the sheet again. In addition it locks these cells from the user.

Now the issue here is with the Range().Value statement. This statement seems to cause issues with the next Range.Locked statement. The error states that it is unable to set property on Range Class. I tried placing the statement before the Interior.Color statement and it issued a similar error relating to the interior.color statement.

I would like to know why am I getting this error and does the Range.Value statement affect the protection in anyway. Without the Range.Value statement the code executes properly.

Thanks in advance,



Sponsored Link
Ads by Google

Response Number 1
Name: rhawk7938
Date: July 12, 2006 at 15:04:54 Pacific
Reply:

I think your problem is with the locked property. It works only if the worksheet is protected. Your first statement unprotects the sheet.


0

Response Number 2
Name: rhawk7938
Date: July 12, 2006 at 16:31:42 Pacific
Reply:

See if this works:

Private Sub Workbook_Change(ByVal Sh As Object, ByVal Target As Range)

Worksheets("Sheet1").Unprotect

ActiveSheet.Range("C3:C120").Locked = False

With Range("C10:C13")
.Locked = False
.Interior.Color = RGB(211, 211, 211)
.Value = 0
.Locked = True
End With

Worksheets("Sheet1").Protect

End Sub


0

Response Number 3
Name: hrajan
Date: July 13, 2006 at 04:40:32 Pacific
Reply:

Alrighty,
I found the issue. Since the routine is a Change routine any change in the worksheet triggers this routine. Hence when I assign a value to a cell, this function is called again (loops in itself) and is executed once again before returning to the statement after the value assignment statement. At the end of the routine I'm protecting the worksheet due to which any changes made to it throws errors.

Thanks anyway for your advice. It is appreciated.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Cell Protection

cells protection in excel www.computing.net/answers/office/cells-protection-in-excel/7649.html

freeze cells or something similar? www.computing.net/answers/office/freeze-cells-or-something-similar/6106.html

Conditional Cell Range www.computing.net/answers/office/conditional-cell-range-/6014.html