title: MergeCells with defined range (Run-time error 1004)
body: <p>I'm trying to merge cells based on two cell values that change according to user input but am having probems with the following code: </p>
  
  <pre><code>    SafB = 5 + 2 * Sheets("LinksTable").Range("X2").Value - 2 * Sheets("LinksTable").Range("W2").Value
      SafE = 5 + 2 * Sheets("LinksTable").Range("X2").Value - 1
  
      Set SafRB = Sheets("Report").Range("B1").Offset(SafB - 1, 0)
      Set SafRE = Sheets("Report").Range("C1").Offset(SafE - 1, 0)
  
      Sheets("Report").Range("SafRB:SafRE").MergeCells = True
  </code></pre>
  
  <p>For example, cells W2 and X2 will have values that change depending on how many metrics are selected for a given lever, in this case "Safety". So if the user selects 2 metrics for the Safety lever, W2 = 2 (number of metrics for that lever) and X2 = 2 (cumulative number of metrics in the report; safety being the first lever, the cumulative equals the total in this case). </p>
  
  <p>Given the above code, SafB=5 and SafE=8. Therefore the cells I need to merge are B5:C8.</p>
  
  <p>However, I get the following error message whenever I run the above code:</p>
  
  <blockquote>
    <p>"Run-time error '1004': Application-defined or object-defined error".</p>
  </blockquote>
  
  <p>Any help would be greatly appreciated!</p>