title: How do I fix error 1004 in vba excel when trying to unlock some cells?
body: <p>I know that there are already a bunch of threads on error 1004, but after digging through them I haven't found a situation similar to mine. I'm trying to lock a workbook except for a range of cells, using the info I found <a href="https://stackoverflow.com/questions/3037400/how-to-lock-the-data-in-a-cell-in-excel-using-vba">here</a> and the following code:</p>
  
  <pre><code>If SecurityActive= "yes" Then
      Worksheets("Invullen").Range("D7, D9, D11, D15, D17, D19, D23, J12, J14:J16").Locked = False
  
      'INVULLEN
      Worksheets("Invullen").Protect UserInterfaceOnly:=True
      'AFDRUKKEN
      Worksheets("Afdrukken").Protect UserInterfaceOnly:=True
      'AFDRUKKENBEFR
      Worksheets("AfdrukkenBEfr").Protect UserInterfaceOnly:=True
      'BENL
      Worksheets("BEnl").Protect UserInterfaceOnly:=True
      'BEFR
      Worksheets("BEfr").Protect UserInterfaceOnly:=True
      'NL
      Worksheets("NL").Protect UserInterfaceOnly:=True
      'FR
      Worksheets("FR").Protect UserInterfaceOnly:=True
      'UK
      Worksheets("UK").Protect UserInterfaceOnly:=True
      'DE
      Worksheets("DE").Protect UserInterfaceOnly:=True
      'TECHNISCH
      Worksheets("Technisch").Protect UserInterfaceOnly:=True
  
  End If
  </code></pre>
  
  <p>SecurityActive is a variable I use to be able to quickly change wether I want to secure the workbook or not. The error highlights the second line of the code. Does anyone how to fix the error?</p>