View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Using VBA to Unlock Cells

the unqualified Cells pertains to the activesheet which many not be sheet3

Public Sub Workbook_Open()
ThisWorkbook.Sheets(3).Range("L4").Value = NextSeqNumber
ThisWorkbook.Sheets(3).Range("data1").Value = Date
With Sheet3
.Unprotect
.Cells.Locked = True
'Unlock cells for data entry
.[E12:E15, G14, I14, L13:L15, K14:K15, D18:K34, G37:G38,
D37:D39,
E40:E41, F42].Locked = False
.Protect UserInterfaceOnly:=True 'Protect worksheet
End With
End Sub

You need periods before Cells and [E12:E15, . . .

--
Regards,
Tom Ogilvy

"Office User" wrote in message
...
I added the suggestions from Paul and Harald but still getting the same

error
message: Run time error 1004 Unable to set the Locked property of the

Range
class.

Here's the code now:
Public Sub Workbook_Open()
ThisWorkbook.Sheets(3).Range("L4").Value = NextSeqNumber
ThisWorkbook.Sheets(3).Range("data1").Value = Date
With Sheet3
.Unprotect
Cells.Locked = True
'Unlock cells for data entry
[E12:E15, G14, I14, L13:L15, K14:K15, D18:K34, G37:G38,

D37:D39,
E40:E41, F42].Locked = False
.Protect UserInterfaceOnly:=True 'Protect worksheet
End With
End Sub

Thanks for any input.
Marcia

"Paul Martin" wrote:

Hi Marcia

If I'm applying .Protect to a WorkSheet, I like to use the
UserInterfaceOnly argument like so:

Sheet3.Protect, , , True or
Sheet3.Protect UserInterfaceOnly:=True

That way your worksheet is protected but any macros you write are not
affected by the protection (ie, you can change a value on a worksheet
while it is protected, which a user cannot do)

Regards

Paul Martin
Melbourne, Australia