<p>Try using<br>
Worksheet.Protect “Password”, UserInterfaceOnly := True</p>
<pre><code class="lang-auto">
If theUserInterfaceOnly` parameter is set to true, VBA code can modify protected cells.
Note however that this parameter does not stick. It needs to be reapplied each time the file is opened.</code></pre>