Andy,
By default, all cells are locked so when you Protect the sheet (from the
Tools menu, Protection item), all cells will be uneditable. Select the cells
you want to be able to change, go to the Format menu, choose Cells, then the
Protection tab. There, uncheck the Locked option, enter a password if
desired, and then protect the sheet. Only those cells that you unlocked will
be editable. All other cells on the sheet will be locked.
Protecting a cell prevents it from being changed by either the user or VBA
code. If you want to allow VBA code to change any cell but still keep the
user from changing a cell, leave the cell Locked but protect the sheet via
VBA code using the UserInterfaceOnly option. In the ThisWorkbook code
module, use
Private Sub Workbook_Open()
ThisWorkbook.Worksheets("SheetName").Protect UserInterfaceOnly:=True ' ,
Password:="abc" ' password if desired
End Sub
Now, VBA code can change any cell but the user is still locked out. Note
that the UserInterfaceOnly option is available only via code (there is no
menu item or command button for it) and it does not get saved with the
workbook. You must set the property whenever the workbook is opened.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)