Range won't Unlock

G

Guest

I have code that locks the majority of the cells in my spreadsheet. I then have code that unlocks a group of those cells. The code that unlocks the cells gives me a run-time error 1004: Unable to set the Locked property of the Range class. I don't understand why I'm getting this error. The .Locked = False line is the problem line. The syntax looks right. Any help would be great. Thanks in advance. The code follows

Private Sub optNonUniformed_Click(
Worksheets("TIME AND LEAVE").Protect UserInterfaceOnly:=Tru
Range("A5:p40").Interior.ColorIndex = 2
Range("A5:p40").Locked = Tru
Range("C5:p5,A6:B9,A12:B15,D16,F16,H16,J16,L16,N16,P16,N34:N40,D10:D11,F10:F11,H10:H11,J10:J11,L10:L11,N10:N11,P10:p11,C13:p15,C34:C40").Interior.ColorIndex = xlNon
Range("D10:D11,F10:F11,H10:H11,J10:J11,L10:L11,N10:N11,P10:p11,C13:p15,C34:C40").Locked = Fals
End Sub
 
V

Vasant Nanavati

Your code works for me as is in Excel 2K. I just copied, pasted and ran it
with no problems.

--

Vasant


Matt said:
I have code that locks the majority of the cells in my spreadsheet. I then
have code that unlocks a group of those cells. The code that unlocks the
cells gives me a run-time error 1004: Unable to set the Locked property of
the Range class. I don't understand why I'm getting this error. The .Locked
= False line is the problem line. The syntax looks right. Any help would be
great. Thanks in advance. The code follows.
Private Sub optNonUniformed_Click()
Worksheets("TIME AND LEAVE").Protect UserInterfaceOnly:=True
Range("A5:p40").Interior.ColorIndex = 24
Range("A5:p40").Locked = True
Range("C5:p5,A6:B9,A12:B15,D16,F16,H16,J16,L16,N16,P16,N34:N40,D10:D11,F10:F
11,H10:H11,J10:J11,L10:L11,N10:N11,P10:p11,C13:p15,C34:C40").Interior.ColorI
ndex = xlNoneRange("D10:D11,F10:F11,H10:H11,J10:J11,L10:L11,N10:N11,P10:p11,C13:p15,C34:C
40").Locked = False
 
D

Dave Peterson

There's a bug in xl97 (fixed in xl2k) that deals with code called from controls
from the control toolbox toolbar that are used on a worksheet.

One fix is to change the .takefocusonclick property to false.

Another fix is to add:
activecell.activate
at the top of your code.

since the optionbuttons (it is an option button???) don't have the
..takefocusonclick property, you can use the
second suggestion.
 

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