title: Excel VBA Unlocking cells to run a macro then locking again
body: <p>Certain cells in my workbook are locked which unfortunately prevents a macro from running. So, I modified the macros located here <a href="http://excel-macro.tutorialhorizon.com/excel-vba-range-lockunlock-specific-cells/" rel="nofollow">http://excel-macro.tutorialhorizon.com/excel-vba-range-lockunlock-specific-cells/</a> to unlock the sheet, run a macro and then relock. I just wanted to post a solution. </p>
  
  <pre><code>Sub sumit2()
    'Unlocks cells A1:C5
   Dim mainworkBook As Workbook
  
   Set mainworkBook = ActiveWorkbook
  
     ActiveSheet.Unprotect Password:="xx"
  
  
     mainworkBook.Sheets("Sheet1").Range("A1:C5").Locked = False
  
    Call FillCell
  
    End Sub
  Sub FillCell()
  
    Dim mainworkBook As Workbook
  
    Set mainworkBook = ActiveWorkbook
  
    mainworkBook.Sheets("Sheet1").Range("A1:C5").Value = "Locked"
  
  Call sumit
  End Sub
  Sub sumit()
  'Protects cells A1:C5
    Dim mainworkBook As Workbook
  
    Set mainworkBook = ActiveWorkbook
  
      ActiveSheet.Unprotect Password:="xx"
  
  
     mainworkBook.Sheets("Sheet1").Range("A1:C5").Locked = True
  
     ActiveSheet.Protect Password:="xx"
  
  
   End Sub
  </code></pre>