title: Using a variable in a VBA IF statement
body: <p>I have a working IF statement in a VBA Module.
  The IF statement checks a date in a table is between two dates and returns a TRUE or FALSE that can be used by a subsequent Pivot Table to sum values from the Table.  I am working with European dates.</p>
  <pre><code> lColName.DataBodyRange.Formula = &quot;=IF(AND([@Date] &gt;=$G$1,[@Date] &lt;=$H$1),&quot;&quot;TRUE&quot;&quot;,&quot;&quot;FALSE&quot;&quot;)&quot;
  </code></pre>
  <p>The dates are in $G$1 and $H$1 in that sheet for ease of debugging but want to place them on another sheet where I have all the other reference data I use in the workbook.
  So in this Module, before the IF statement, I have set those dates against two variables.</p>
  <pre><code>Worksheets(&quot;References&quot;).Activate
  startdate = Range(&quot;I2&quot;).Value
  enddate = Range(&quot;J2&quot;).Value
  </code></pre>
  <p>Repacing $G$1 and $H$1 with startdate and enddate errors. What syntax should I use to get the IF statement to work?
  Thanks</p>