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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locking Unlocking Cells 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
 
Unless lock_area is really the name of a variable, the syntax you want is probably:
Code:
   range("lock_area").Select
If lock_area is the name of a variable, what does it contain when you break on that line?

If lock_area is not meant as a range name, this is a good illustration of the value of using
Code:
  Option Explicit
as the first line in a module to catch syntax errors like that.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top