vba - How to make a specific cell in excel uneditable -
my problem trying make cell cannot edited users after inputs given. example want let user input cell c22-c28
after user inputs cell, specific cell shouldn't edited. should best solution this? suggestions?
take @ question how lock data in cell in excel using vba
where multiple nice answers. in basic, need set range .locked
, protect sheet via .protect
, more develop info try @ msdn
edit: can use mentioned in question (restricting user delete cell contents)
without lock , unlock, can use this. have there 1 global variable store selection value (to preserve beforechange state). function selectionchange, updating value of current cell, can restore cell value after users try.
sub worksheet_change controling, if user targeting specified row , column (can adjusted whole range), , if try change value, prompted , value set back.
dim prevvalue variant private sub worksheet_selectionchange(byval target range) prevvalue = target.value end sub private sub worksheet_change(byval target range) if target.row = 5 , target.column = 5 if target.value <> prevvalue target.value = prevvalue msgbox "you not allowed edit!", vbcritical + vbokonly end if end if end sub
Comments
Post a Comment