Unable to set the Locked property of the range class

S

Stuart

Here's the code:

Option Explicit
Private Sub Workbook_Open()

Dim i As Integer, C As Range
With Workbooks("MasterOrder.xls").Worksheets("Master Order")
.Unprotect Password:="SGB"
.Cells.Locked = False
i = .Range("I10").Value
.Range("I10").Value = i + 1
For Each C In .Range("A1:N61")
With C
If Not C.Interior.ColorIndex = 34 Then
C.Locked = True
End If
End With
Next
.Protect Password:="SGB"
.EnableSelection = xlUnlockedCells
End With
End Sub

Q1: why that error message please?
Q2: can I improve the code please?

Regards.
 
R

Ron de Bruin

Try this Stuart

For Each C In .Range("A1:N61")
If C.Interior.ColorIndex <> 34 Then
C.Locked = True
End If
Next
 
S

Stuart

Ron,

Manythanks ....but same error message.

BTW this is Excel 2000 under Win 2K.

Regards and thanks.
 
S

Stuart

It seems to run, but then fail on the same cell each time,
namely "K12". This cell is merged with "L12".

Could merged cells be the problem?

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top