title: Using VBA to unprotect cells
body: <p>So I have a spreadsheet that I want to format based on user inputs, but the cells need to remain locked until it is determined by the formatting that they will be user input cells.
  I have code that will look the cells for the user interface only but allow VBA to edit them.</p>
  
  <pre><code>&gt; 'protects all sheets upon opening work book
  &gt;     Me.Worksheets("Sheet1").Protect "Password", UserInterfaceOnly:=True
  &gt;     Me.Worksheets("Sheet2").Protect "Password", UserInterfaceOnly:=True
  &gt;     Me.Worksheets("Sheet3").Protect "Password", UserInterfaceOnly:=True
  </code></pre>
  
  <p>so now I need to allow the following cells to be editable by the user</p>
  
  <pre><code>Sheets("Sheets2").Protection.AllowEditRanges.Add "Test", Range("C2", "C8")
  Sheets("Sheets2").Protection.AllowEditRanges.Add "Test", Range("H6")
  Sheets("Sheets2").Protection.AllowEditRanges.Add "Test", Range("K6")
  </code></pre>
  
  <p>I have tried allowing edits before I lock the sheet and after. 
  What I'd really like is some VBA code to unlock the cells after applying formatting rather than defining which cells might be editable in advance.
  Any help gratefully appreciated :)</p>