title: VBA unprotect cells according to colorindex - run time error
body: <p>I'm new to the forum but have to admit I've used VBA code from this forum on many occasions. It's a great resource. However I have been unable to get my latest code to run properly. PS My VBA skills are limited.</p>
  
  <p>My problem:</p>
  
  <p>I have several identically formatted worksheets within a workbook. Columns in the worksheets are either classified as "actual" data or "forecast" data. Cells in the "forecast" column are conditionally formatted to be yellow (color index 36).</p>
  
  <p>What I want to do is to lock every cell in the used range on each sheet that isn't yellow to prevent users from changing cells that contain actual data.</p>
  
  <p>I borrowed the code below and made some tweaks - I can step through without issues but when I run it fully a get the 1004 run time error. I suspect it's something to do with protecting the sheets. I did have the code set to run for each sheet in the workbook but have changed it to "activesheet" to try and isolate the problem.</p>
  
  <p>Any advice would be greatly appreciated.</p>
  
  <pre><code>Option Explicit
  
  Sub LockExceptYellowCells()
  Dim ws As Worksheet
  Dim c As Range
  
      ActiveSheet.Unprotect
          For Each c In ActiveSheet.UsedRange
          If c.Interior.ColorIndex &lt;&gt; 36 Then
          c.Locked = True
          Else
          c.Locked = False
          End If
  
      Next c
  
      ActiveSheet.Protect
  
  End Sub
  </code></pre>