excel - Restricting the user to delete the cell contents -


is there's way restrict user deleting cell contents without using protect method of excel. have code:

private sub worksheet_beforedoubleclick(byval target range, cancel boolean) dim ws worksheet set ws = thisworkbook.worksheets("sheet1")     if not intersect(target, range("c21:d" & ws.range("c" & ws.rows.count).end(xlup).row)) nothing          cancel = true          msgbox "you not allowed edit!", vbcritical + vbokonly     endif end sub 

but disallows editing of cell contents. want make function disallow editing , deleting data in cell without using protect method. thanks!

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 

edit: disable editing every cell not empty

private sub worksheet_change(byval target range)        if prevvalue <> ""          if target.value <> prevvalue             target.value = prevvalue               msgbox "you not allowed edit!", vbcritical + vbokonly          end if      end if   end sub 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -