title: 'Object variable or With block variable not set' error when setting a range in VBA
body: <p>I have a function that creates a Pivot Table, but I am getting an error when I try to set a range that will be merged and have a title added to it.</p>
  
  <p>In the below code, <code>pivot_title_range</code> is a 'String' variable, and is optional when calling the function. <code>title_range</code> is a 'Range' variable. Both lines that set the range (whether or not the users declares <code>pivot_title_range</code>) cause the same error.</p>
  
  <pre><code>If pivot_title_range = "" Then
      title_range = ActiveSheet.Range("B3:E4")
  Else
      title_range = ActiveSheet.Range(pivot_title_range)
  End If
  </code></pre>
  
  <p>Here is the error that I am getting -</p>
  
  <pre><code>Run-time error '91':
  Object variable or With block variable not set
  </code></pre>
  
  <p>If required, here is a Pastebin of the full function - <a href="http://pastebin.com/L711jayc" rel="nofollow">http://pastebin.com/L711jayc</a>. The offending code starts on line 160.</p>
  
  <p>Is anybody able to tell me what I am doing wrong? Thanks.</p>