title: Range object not passing into Function Excel VBA
body: <p>This seems like a simple thing to solve but I don't quite understand the issue. I have a function that take a Range parameter but when I use a Loop, it doesn't seem to recognise it (I get a 424 - object error). Code provided below.</p>
  
  <pre><code>Sub PrintKeys(Data As Variant, C1 As Range)
  Dim key As Variant
  Dim Rg As Range
  Set Rg = C1
  Dim i As Integer
  i = 1
  For Each key In Data.Keys
      'Rg.Offset(0, i).Value = key
      'Rg.Offset(0, i).Interior.ColorIndex = 15
      Rg = Rg.Offset(0, i)
      Rg.Value = key
      Auto_Colour (Rg)
      i = i + 1
  Next key
  End Sub
  
  Sub Auto_Colour(Rg As Range)
      Rg.Interior.ColorIndex = 15
  End Sub
  </code></pre>
  
  <p>If I change the above to then it works:</p>
  
  <pre><code>Sub PrintKeys(Data As Variant, C1 As Range)
  Dim key As Variant
  Dim Rg As Range
  Set Rg = C1
  Dim i As Integer
  i = 1
  For Each key In Data.Keys
      Rg.Offset(0, i).Value = key
      Rg.Offset(0, i).Interior.ColorIndex = 15
      i = i + 1
  Next key
  End Sub
  </code></pre>
  
  <p>Based on the above, Rg is a Range object but the former example isn't able to pass it into the Auto_Colour function despite the function accepting a Range.</p>
  
  <p>What am I missing?</p>
  
  <p>Thanks in advance.</p>