Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locking Cells & Protecting Excel Sheets via VBA

Status
Not open for further replies.

RougeDev

Programmer
Jun 26, 2002
10
US
Ok I'm using Excel '97 & I've got a spreadsheet that is filled out by means of a form dialogue. Now after the user has finished with the form entries are placed in the spreadsheet. I need to lock some of the cell that have been entered & leave others free for editing manually

I was trying to do this:

Private Sub AddNewLine_Click()

Worksheets("List").Unprotect

UserForm1.Show

Worksheets("List").Protect DrawingObjects:=False, Contents:=True, Scenarios:=False

End Sub

& as part of one of the events in the form I've embeded:

range(lock_area).Select
Selection.Locked = True
Selection.FormulaHidden = False


The problem is that the Unprotect method of the worksheet fails, so I acheive nothing!!!!


Any help that you could offer would be muchly appreciated
 
See my post in thread68-459165

(You're right -- this is a more appropriate forum for your question.)
 
Ok Read your post.

lock_area is a variable which contains the a cell address or range eg "C6" or "C6:D6"

But that's unimportant at first as it's the
Worksheets("List").Unprotect
line that pukes.....
Unprotect method of the worksheet failed etc.
 
I would need to see more of your code. It works ok for me.
 
Might be a silly question but is the worksheet PASSWORD protected - if so, you need
sheets("Sheetname").unprotect password:= "whateverthepasswordis" Rgds
Geoff

Estne volumen in toga, an solum tibi libet me videre?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top