excel - How do I lock cells containing formulas but still allow macros to work? -


i have worksheet make employees fill out, , have calculated cells want lock cannot change them. have selected cells , selected properties , ensured "lock" checkbox checked. when protected worksheet/workbook "export csv" macro button stopped working. in order enable macro completed inserted vb code workbook:

private sub workbook_open()  dim wsheet worksheet each wsheet in worksheets      wsheet.protect password:="password", _     userinterfaceonly:=true  next wsheet   end sub 

this worked had unintended side effect of allowing locked formulas able edited though locked. cells containing non-formula values remained locked. proper way allow macros still lock formula cells?

my solution lock entire workbook , worksheets, code vb button disabling of lock re-enabling macro. so:

sub mymacro()  sheet1.unprotect password:="password"      'insert code here      sheet1.protect password:="password"  end sub 

i deleted workbook_open code.


Comments