title: Lock/unlock cells VBA
body: <p>I have been looking for a code to lock all the cells in a sheet but one  and I found this code:</p>
  
  <pre><code>Worksheets("SW").Range("D2").Locked = False
  Worksheets("SW").Protect UserInterfaceOnly:=True
  </code></pre>
  
  <p>it really worked fine until I saved it and closed/opened the file again, then any macros I had were  run.</p>
  
  <p>I guess it is because in that sheet I have different macros and also I have the macro that runs when a cell is changed:</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  </code></pre>
  
  <p>Do you have any idea how to make it work?</p>
  
  <p>One more thing, this workbook it will be shared, so I don't know that will affect the macros.</p>
  
  <p>sorry maybe I was too ambiguous. </p>
  
  <p>Yes I want to prevent others to change de value of the cells.</p>
  
  <p>I want that just one cell could be changed so all the others are changing with the macros.</p>
  
  <p>Thanks again for all your help</p>
  
  <p>PS: yes  Ahmad Al-Mutawa, I want to be impossible to chang the sheet even after the project being saved, closed and opened.</p>
  
  <p>If you need more info just tell me I'll try to be more specific.</p>