LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Protecting cells with VBA (Excel 2003)

In my application a user makes a choice using a dropdown box in cell k44.
Depending on the choice, I then run some code to put some data in some other
cells, k59 and k61-64, which I subsequently want to protect programmatically
from being changed manually.
I get an error saying the program cannot set the .Locked property of the
cells.

I have these cells unlocked in the sheet. In the code, I unprotect the sheet
before attempting to change the cells' properties. Below is the code I use.
Any ideas ?

Private Sub Worksheet_change(ByVal Target As Range)
....
....some Dim statements
....
Application.ScreenUpdating = False
Application.EnableEvents = False
Sheet10.Unprotect Password:="somepwd"

On Error GoTo ErrHand

....
....some other stuff
....

Err = "k44"

If Not Intersect(Range("k44"), Target) Is Nothing Then

Select Case Range("k44").Value

Case "...."

Case "...."


Case "Customer"
Range("L51").Value = "0"
Range("K51").Value = "0"

Range("k59").Value = "=VLOOKUP($K$35,'Pop
Addresses'!$A$2:$N$18,2)"
Range("k61").Value = "=VLOOKUP($K$35,'Pop
Addresses'!$A$2:$N$18,4)"
Range("k62").Value = "=VLOOKUP($K$35,'Pop
Addresses'!$A$2:$N$18,5)"
Range("k63").Value = "=VLOOKUP($K$35,'Pop
Addresses'!$A$2:$N$18,6)"
Range("k64").Value = "=VLOOKUP($K$35,'Pop
Addresses'!$A$2:$N$18,7)"
Range("k59").Locked = True---------jumps to ErrHand
here------- Range("k61:k64").Locked = True

....
....some other stuff
....

End If

ErrHand:
If Err < "" Then
Result = MsgBox("Error occurred excuting " & Err & " change event",
vbOKOnly, "Error")
End If
ActiveSheet.Protect Password:="somepwd"
Application.EnableEvents = True
Application.ScreenUpdating = True

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
Protecting a file in Excel 2003 KrisP Excel Discussion (Misc queries) 1 November 9th 06 06:08 PM
protecting formula cells in excel 2003 [email protected] Excel Discussion (Misc queries) 2 March 14th 06 07:24 PM
Excel 2003 - Protecting and Hiding Columns Peppermint Excel Discussion (Misc queries) 2 January 19th 06 04:06 PM
Protecting Headers & Footers in Excel 2003 LondonLion Excel Discussion (Misc queries) 1 September 22nd 05 01:53 PM
Protecting Workbooks in Excel 2003 Misha Excel Discussion (Misc queries) 1 June 23rd 05 07:41 AM


All times are GMT +1. The time now is 02:38 PM.

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

About Us

"It's about Microsoft Excel"