title: Excel VBA: .Formula IF with variables - How to insert quotation marks?
body: <p>Thanks to mirabeau @ Mrexcel for original script.</p>
  
  <p><strong>What the original code does</strong>
  Sums every range in the K column and adds total to end</p>
  
  <p><strong>What I want it to do</strong>
  Replace the sum with a sumif that sums only the cells meeting the criterion cell, unless the criterion cell containts "Bloomingdales*". Then the entire range should be summed.</p>
  
  <p><strong>The issue</strong>
  I am checking if formula cell.offset(-4,-10) equals the exception. I am however having troubles mixing variables and strings and even variables and variables. Ideally, it should check if e = Store or if e = "Bloomingdales*". Either the code won't execute, or I only get it to display "e=store", where Excel can't interpret the VBA variables.</p>
  
  <p>My attempt: </p>
  
  <pre><code>Sub addups()
  Dim e As Range, f As Range, g As Range, u As String, x As Range, Store As String
  Set e = Columns("K").Rows(2) 'any column and/or start row you like
  If e = "" Then Set e = e.End(4)
  Do
  Set g = e
  If e.Offset(1) &lt;&gt; "" Then Set e = e.End(4)
  u = Range(g, e).Address(0, 0)
  Set f = e.Offset(1)
  Set e = e.End(4)
  Set x = f.Offset(-4, -10)
  Store = "Bloomingdales*"
  f.Formula = "=IF("&amp; x &amp;" = "&amp;Store&amp;",Sum(" &amp; u &amp; "),Sumif(A:A," &amp; x.Address &amp; ", K:K))"'Error
  Loop Until e.Row = Rows.Count
  End Sub
  </code></pre>
  
  <p>Please let me know if you need more info. Cheers!</p>