View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Nigel Nigel is offline
external usenet poster
 
Posts: 923
Default cell locking via VBA

Cell or Cells (a range) can only be protected by applying protection to the
worksheet. If the cells in question are locked then protecting the
worksheet will protect the cells (and all other cells that are locked!).

Normally you would unlock the cell(s) you wish the user to change then apply
protection to the worksheet. Switching the cell locking and worksheet
protection on and off under programme control based on conditions or events
in the workbook or worksheet are all possible.

The following will unlock the range A1 to B3, allowing the user to edit the
cells after the worksheet is protected.

ActiveSheet.Unprotect
Range("A1:B3").Locked = False
ActiveSheet.Protect

The following reverese this situation

ActiveSheet.Unprotect
Range("A1:B3").Locked = True
ActiveSheet.Protect



--
Cheers
Nigel



"aken" wrote in message
...
hi,

how can a cell be locked via VB scriprting in excel. to say, Cell A1 must

be
locked if cell B1's value is less then (or any other conditions), say 35.
also, depending upon some condition, can the whole range of cells say
renge(A1:A40) also be locked???

as such the only way what am doing is: select the cell - format - cells -
protection tab - check-mark locked. this is manual setting, can this work

be
done programatically??? that is what am on to.

i have tried by going to all the things like VB's programming codes that i
can go but just cant get the result.

any help will be truely appreciated.

taken