title: VBA Linear Regression Analysis with Button
body: <p>I am running a fairly large macro that includes running a linear regression analysis from the Analysis Toolpak.</p>
  
  <p>When I run it through the separate VB window, it runs just fine, but after creating a form control button and assigning the same macro to it, it does not work.</p>
  
  <p>The linear regression analysis creates a new page as desired:
  <a href="https://i.stack.imgur.com/pQUiN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pQUiN.png" alt="new page"></a></p>
  
  <p>But it replaces the analyzed data with the cell formatting from the analysis:
  <a href="https://i.stack.imgur.com/T4XH4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T4XH4.png" alt="cell formatting"></a></p>
  
  <p>Can anybody help me to make the button run the sub properly?</p>
  
  <p>This is the code that I used to call the linear regression:</p>
  
  <pre><code>Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range(loc1(1), loc1(2)), _
      ActiveSheet.Range(loc1(3), loc1(4)), False, True, 99, "Regression " &amp; tabname, True, _
      True, True, True, , False
  </code></pre>