title: Is there a way to use VBA for Excel to output a formula to a specific cell in an Excel worksheet?
body: <p>I am fairly new at programming. I feel like this should be a simple fix but I cannot find anything that works. I am trying to use a <code>Select Case</code> structure to write a different formula to a cell depending on the selected case. If I type:</p>
  
  <pre><code>Sheet1.Range("g10").Value = "=IF(SUM(F10)&gt;0,SUM((F10-15)),"")" 
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>Run-time error '1004'<br>
    Application-defined or object-defined error. </p>
  </blockquote>
  
  <p>I can get it to work if I include spaces like so:</p>
  
  <pre><code>Sheet1.Range("g10").Value = " =IF(SUM(F10)&gt;0,SUM((F10-15)),"") "
  </code></pre>
  
  <p>but then Excel puts it into the cell like text, not as a formula (it doesn't <strong>do</strong> anything).</p>
  
  <p>I have tried a few different methods but have run into the same issue. Is it possible to do this?</p>
  
  <p>I apologize if this has been asked and answered, but I wasn't able to find anyone referencing this specific problem.</p>