title: Storing Range attributes as an object?
body: <p>I'm having trouble with the way I designed this little report I'm making.  Is it possible to create a variable for a Range object in Excel VBA, for the purposes of applying the formatting to another Range?  Here is my example:</p>
  
  <p>I'm creating a dictionary from the Microsoft Scripting Runtime library:</p>
  
  <pre><code>Dim d as Scripting.Dictionary
  </code></pre>
  
  <p>With this I'm adding labels, values, and (trying to add) Ranges.</p>
  
  <pre><code>Dim rng as Range    
  
  rng.Font.Bold = True
  d.Add 1, Field("test1", 12345, rng)
  rng.Font.Bold = False
  d.Add 2, Field("TestTwo", "Testing field", rng)
  rng.HorizontalAlignment = xlCenter
  d.Add 3, Field("threeeee", 128937912, rng)
  
  Dim key As Variant
  
  For Each key In d.keys
      Range("A" &amp; key).value = d(key).Label
      Set Range("B" &amp; key).value = d(key).rng
  
  Next key
  </code></pre>
  
  <p>Here is my Field function:</p>
  
  <pre><code>Private Function Field(Label As String, val As Variant, rng As Range) As cField
  
      Dim f As New cField
      f.Label = Label
      f.val = val
      Set f.rng = rng
      Set Field = f
  
  End Function
  </code></pre>
  
  <p>And here is my cField class:</p>
  
  <pre><code>Option Explicit
  
  Dim mVarValue As Variant
  Dim mStrLabel As String
  Dim mRng As Range
  
  Property Let val(ByVal val As Variant)
      mVarValue = val
  End Property
  
  Property Get val() As Variant
      val = mVarValue
  End Property
  
  Property Let Label(ByVal val As String)
      mStrLabel = val
  End Property
  
  Property Get Label() As String
      Label = mStrLabel
  End Property
  
  Property Let rng(ByVal val As Range)
      Set mRng = val
  End Property
  
  Property Get rng() As Range
      Dim a As Range
      a.value = mVarValue
      Set rng = a
  End Property
  </code></pre>
  
  <p>The idea is that the key in the dictionary is going to be the row location for the field.  This way if changes need to be made to the report I'm making, the only thing that needs to be changed is the key for that particular value in the dictionary.  I have been successful storing the label for the value, and the value itself, but I also want to store the formatting for that Range (bold, justification, borders, etc...).</p>
  
  <p>I get a 'Run-time error '91': Object variable or With block variable not set' error on the line immediately following the rng declaration.  I'm wondering if its not possible to have a generic Range that doesn't have a location on a sheet, or if somehow my syntax is off.</p>
  
  <p>Any help would be greatly appreciated! :)</p>