title: VBA: Protection.AllowEditRanges with dynamic range
body: <p>Yesterday I asked a question (<a href="https://stackoverflow.com/questions/33263658/marking-an-area-with-a-double-for-loop/33264105#33264105">Marking an area with a double &#39;For&#39; loop</a>) and @Excel Hero gave me a nice response. I have used his code to store a range in a variable 'k':</p>
  
  <pre><code>Sub ErosRam()
      Dim i&amp;, j&amp;, area$, k As Range, r As Range
  
      Const COL_PERIOD = 3
      Const ROW_PERIOD = 3
      Const REPS_HORIZONTAL = 3
      Const REPS_VERTICAL = 2
  
      Set r = [f7:g8]
      Set k = r
  
      For i = 0 To REPS_VERTICAL - 1
          For j = 0 To REPS_HORIZONTAL - 1
              Set k = Union(k, r.Offset(i * ROW_PERIOD, j * COL_PERIOD))
          Next
      Next
  
      area = k.Address(0, 0)
      MsgBox area   
  End Sub
  </code></pre>
  
  <p>Now, I wish to keep the area given by 'k' unlocked, and lock the rest. So I wish to use something like:</p>
  
  <pre><code>     ActiveSheet.Protection.AllowEditRanges.Add Title:="test", Range:=Range(k)
  </code></pre>
  
  <p>But this does not work. How can I use a variable range inside of protection.alloweditranges?</p>